laravel spatie get all users with role code example
Example 1: get users of specific role laravel role spatie
$users = User::role('writer')->get();
Example 2: laravel get all users except role spatie
You can make 2 querys to get both groups of users that you want. I mean:
1) Users who dont have any role.
User::whereDoesntHave('roles')->get();
2) Users have any role, but not admin (from Adam Kozlowski answer)
$this->users()->whereHas('roles', function ($query) {
$query->where('name','!=', 'admin');
});