roles icon indicating copy to clipboard operation
roles copied to clipboard

Can't get roles / permissions of other user? (not the one who is logged in)

Open muneebarif11 opened this issue 8 years ago • 2 comments

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?

muneebarif11 avatar Jun 03 '16 18:06 muneebarif11

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.

PCoetzeeDev avatar Jun 15 '16 20:06 PCoetzeeDev

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);

chandzul avatar Jul 15 '16 19:07 chandzul