Find all users with specific Roles in Entrust for Laravel 5

271 Views Asked by At

I have used Entrust for Laravel 5, and I am creating a page in the admin where it displays all the users with 'customers' role. From the documentation, I know how to get a user's role but what I want is to get all the users that has the same roles.

1

There are 1 best solutions below

0
On BEST ANSWER

I believe Entrust sets up the user/roles relationships for you so you'd just do the same thing you would normally do without Entrust.

$customers = User::whereHas('roles', function($query)
{
    $query->where('name', 'customer');
})->get();