Reputation: 178
I wanted to show list of users those are having permission 'x'. I am using zizaco/entrust plugin in laravel 5.1 for managing roles/permissions. I have setup roles and permissions already. Previously i was working with roles but change of specs i need it by permissions wise.
Upvotes: 0
Views: 491
Reputation: 5368
You can use whereHas()
:
$permissionName = 'x';
$userList = User::whereHas('roles.perms', function($query) use ($permissionName) {
$query->whereName($permissionName);
})->get();
dd($userList);
Upvotes: 0