Kapil Verma
Kapil Verma

Reputation: 178

How to fetch list of users with permission 'x' in zizaco entrust laravel?

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

Answers (1)

baikho
baikho

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

Related Questions