Zizaco / entrust

Role-based Permissions for Laravel 5
MIT License
6.05k stars 1.29k forks source link

count users assigned to roles #928

Open ajoudh opened 6 years ago

ajoudh commented 6 years ago

Basically I just want to count users based on there roles, something like this:

roles          count

 admin              4
 user                 2
$role_name     $User_withthisRole_count

not sure what to do..

mariusberget92 commented 5 years ago

Here is something i personally use: User::whereHas('roles', function($query) { $query->where('id', 1); })->count() to count users based on roles.