-
Notifications
You must be signed in to change notification settings - Fork 336
Querying Data
Carl Olsen edited this page Feb 23, 2017
·
2 revisions
Get users with ability
// add to Users model
public function scopeWhereCan($query, $ability)
{
$query->where(function ($query) use ($ability) {
// direct
$query->whereHas('abilities', function ($query) use ($ability) {
$query->byName($ability);
});
// through roles
$query->orWhereHas('roles', function ($query) use ($ability) {
$query->whereHas('abilities', function ($query) use ($ability) {
$query->byName($ability);
});
});
});
}
$users = User::whereCan($ability);