Comments (6)
Ok this is working, thanks @pxpm.
$user->roles()->get()
Thanks again, loving this package!
from permissionmanager.
You are getting a fresh instance of the db without any roles associated.
You can eager load them with: User::with('roles')->where('name', 'Admin')->first()
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
from permissionmanager.
You are getting a fresh instance of the db without any roles associated.
You can eager load them with:
User::with('roles')->where('name', 'Admin')->first()
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:
How to eager load from loaded object?
$user = backpack_user();
I mean worst case I could do:
User::with('roles')->where('name', backpack_user()->name)->first()
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?)
from permissionmanager.
If you have the traits properly setup in your User model you should be able to just do: bacpack_user()->hasRole('someRoleName')
to check if the user has the desired role. Or ->hasAnyRole(['role1', 'role2'])
etc etc.
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.
from permissionmanager.
Hi @pxpm thanks but I want to get all the roles for a user, not check whether a user has a particular role
from permissionmanager.
backpack_user()->getRolesNames()
return all the user roles for me. Also backpack_user()->roles()->get()
return a collection of role instances.
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 php artisan cache:clear
Let me know if that helps
from permissionmanager.
Related Issues (20)
- Roles index page doesn't load properly. HOT 4
- php artisan migrate, says nothing to migrate HOT 6
- SQLSTATE[HY093]: Invalid parameter number HOT 3
- PermissionManager failing to install on backpack v6 HOT 3
- Add menu item on tabler theme HOT 12
- [Proposal] Please document how to integrate with `laravel-permission` HOT 2
- Login With LDAP HOT 2
- Users can still access the url if they have permisison HOT 2
- Permission Manager Plugin is looking for table users instead of admins HOT 9
- User list not working HOT 2
- [FEATURE] Filtering role and permissions in user CRUD HOT 2
- [Bug] Tests fail possibly trying to load filters on non-PRO setup HOT 7
- Upgrade to `spatie/laravel-permission` v6.1 HOT 5
- Why a new admin account get redirected to /home instead of /admin/dashboard? HOT 6
- How to add 'Select Role(s)' (dropdown) on user create/edit crud view (and get it to save)? HOT 2
- User edit: Default empty password behavior HOT 7
- INDUSTRIAL TRAINING REPORT ON HOT 2
- The attribute [password_confirmation] either does not exist or... HOT 4
- Orderable on columns of type custom_column has not been disabled HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from permissionmanager.