laravel get all users except role spatie

Solutions on MaxInterview for laravel get all users except role spatie by the best coders in the world

showing results for - "laravel get all users except role spatie"
Esteban
11 Nov 2020
1You can make 2 querys to get both groups of users that you want. I mean:
2
31) Users who dont have any role.
4
5User::whereDoesntHave('roles')->get();
6
72) Users have any role, but not admin (from Adam Kozlowski answer)
8
9$this->users()->whereHas('roles', function ($query) {
10    $query->where('name','!=', 'admin');
11});