📌  相关文章
📜  laravel 获取除角色 spatie 之外的所有用户 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:08.548000             🧑  作者: Mango

代码示例1
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');
});