Created
November 11, 2016 20:10
-
-
Save Tucker-Eric/806a1d18e7547a24ded957bf2516b084 to your computer and use it in GitHub Desktop.
Laravel Eloquent Model Trait for querying based on a relationship and including that relationship with the constraints with the results
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Models\Traits; | |
trait WhereHasWithTrait | |
{ | |
public function scopeWhereHasWith($query, $relation, \Closure $closure) | |
{ | |
return $query->whereHas($relation, $closure)->with([$relation => $closure]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment