roles
roles copied to clipboard
Can't get roles / permissions of other user? (not the one who is logged in)
I logged in as an admin and now i want to update users' roles but doing $user->roles() / $user->getRoles() returns null. I can only get roles of user that is logged in .. why?
I haven't tried this myself, but if you have Roles set up correctly, I imagine instantiating a new instance of the user you want should work:
$newUser = User::find($id);
This would then provide you with an instance of the user you are looking for and consequently, $newUser->getRoles() should behave as expected then.
if you want to see what roles have, do this:
$users = User::orderBy('id', 'desc')->paginate(15); foreach ($users as $user) { $user['role'] = $user ->roles() ->select(['slug', 'roles.id', 'roles.name']) ->get(); }
dd($users);