Solution:
I think you forgot to add the trait to the User class:
use Illuminate\Foundation\Auth\User as Authenticatable;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable {
use HasRoles;
// ...
}
If you have not forgotten the trait, then use the below code to get all users roles
and permissions
.
$users = User::all();
$user_roles = [];
$user_permissions = [];
if($users) {
foreach ($users AS $user) {
$user_roles[$user->id] = $user->getRoleNames();
$user_permissions[$user->id] = $user->getAllPermissions();
}
}
FMI SEE: https://spatie.be/docs/laravel-permission/v3/basic-usage/basic-usage