0

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.

Kapil Verma
  • 178
  • 3
  • 17

1 Answers1

0

You can use whereHas():

$permissionName = 'x';

$userList = User::whereHas('roles.perms', function($query) use ($permissionName) {
    $query->whereName($permissionName);
})->get();

dd($userList);
baikho
  • 5,203
  • 4
  • 40
  • 47