1 // laravel count the types of users
2 $roles = Role::pluck('name');
3
4 foreach ($roles as $roleName) {
5 $userCount = User::whereHas('roles', function($query) use($roleName) {
6 $query->where('name', $roleName);
7 })->count();
8 }