-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$user->roles() returning collection of 'false' values #352
Comments
You are getting a fresh instance of the db without any roles associated. You can eager load them with: If you are still not getting the expected roles, you may need to check what guard your roles were created for, and what guard you are using in your admin panel. Cheers |
Thanks a lot @pxpm, but I actually need to get it from authenticated user:
I mean worst case I could do:
but this seems a bit convoluted. Maybe something like $user->loadRoles()? I assume lazyLoading roles is quite difficult then (or why can it not work as with normal relations?) |
If you have the traits properly setup in your User model you should be able to just do: What I suspect is that your authenticated user is using one guard, and there is no roles for that guard. Please read this package README, section 7a) and 7b) that talk a bit about this. Let me know if that helps. |
Hi @pxpm thanks but I want to get all the roles for a user, not check whether a user has a particular role |
If the same is not happening to you, I would check if you roles are properly assigned to the user in the database, and you are using the proper guard for it. If can also be a cache issue, so I would also suggest for you to clear all the caches with Let me know if that helps |
Ok this is working, thanks @pxpm.
Thanks again, loving this package! |
Bug report
What I did:
Trying to get collection of user's roles:
What I expected to happen:
dd($role) to dump an object of type 'Backpack\PermissionManager\app\Models\Role'
What happened:
What I've already tried to fix it:
Have followed all steps as per README.
The user has roles assigned to them (and the roles have permissions assigned to them)
Similar issue: #169
Backpack, Laravel, PHP, DB version:
Backpack/Crud 6.4, Lara 10.x, MySQL 5.7
The text was updated successfully, but these errors were encountered: