PHPackages                             rackbeat/laravel-morph-where-has - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. rackbeat/laravel-morph-where-has

ActiveLibrary[Database &amp; ORM](/categories/database)

rackbeat/laravel-morph-where-has
================================

Fix whereHas for morphTo relations.

2.0(3y ago)759.2k1[2 issues](https://github.com/Rackbeat/laravel-morph-where-has/issues)MITPHPPHP &gt;=7.1CI failing

Since Jul 9Pushed 3y ago1 watchersCompare

[ Source](https://github.com/Rackbeat/laravel-morph-where-has)[ Packagist](https://packagist.org/packages/rackbeat/laravel-morph-where-has)[ RSS](/packages/rackbeat-laravel-morph-where-has/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (5)Versions (9)Used By (0)

Use whereHas for morphed relationships in Laravel
=================================================

[](#use-wherehas-for-morphed-relationships-in-laravel)

Usually, you cant say `whereHas('contact')` if `contact` is a morphTo relationship. This package aims to fix that.

 [![Total Downloads](https://camo.githubusercontent.com/8768f079e90e91f13445bb13dcde21b2e4c621026ea819e6033cc47140f25394/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7261636b626561742f6c61726176656c2d6d6f7270682d77686572652d6861732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rackbeat/laravel-morph-where-has)[![Latest Stable Version](https://camo.githubusercontent.com/65e19ac3a4772dd1e7e8d0d72c0760d2c63a75a8a54a0ba0cad7372b7dd3d95f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7261636b626561742f6c61726176656c2d6d6f7270682d77686572652d6861732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rackbeat/laravel-morph-where-has)[![License](https://camo.githubusercontent.com/a30df7a10dd822576af24c12dfbb8f76fd7fbbf368bfd5accad58694bc6b99f1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f7261636b626561742f6c61726176656c2d6d6f7270682d77686572652d6861732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rackbeat/laravel-morph-where-has)

Installation
------------

[](#installation)

You just require using composer and you're good to go!

```
composer require rackbeat/laravel-morph-where-has
```

The Service Provider is automatically registered.

Usage
-----

[](#usage)

### 1. Add possible variations in your model

[](#1-add-possible-variations-in-your-model)

The problem, is that the morph relationship can have a hard time determining how to handle the `whereHas` call.

Our solution, is that you define every possible morphed class. Like so:

```
