romanbican / roles

Powerful package for handling roles and permissions in Laravel 5
MIT License
1.16k stars 297 forks source link

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

Open muneebarif11 opened 8 years ago

muneebarif11 commented 8 years ago

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?

PCoetzeeDev commented 8 years ago

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.

chandzul commented 8 years ago

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