How to navigate differnet sidebar items depending on daynamic roles ?
Hello ,I am using laravel8 and spatie package for my user management system and i can create different roles dynamical as i want , but what I want is to navigate different sidebar items depends on the users role in the system fro example if the logged in user has the role "admin" there maybe the user management and the role management items in the sidebar and if the user has the "is_darictor" role there may not be those items like in the admins sidebars so how can i control this view using the spatie package in my project! since i am new for this package any one who can help me please!
@aleahy i know that but as i explain the role is dynamic which means it can be created any time and i want manage it dynamical the sidebar menu that is what i want
@luk The parameter passed into the directive is just a string. You can just pass whatever dynamic roles exist as a collection of strings to your view.
Eg:
@foreach($roles as $role)
@role($role)
...
@endrole
@endforeach
@luk navigating items should depend not on the role, but on the permission.
So instead of having @role('admin') in the Blade, which is not dynamic, you should do @can('manage_users') which is permission and is more dynamic. And behind the scenes, you dynamically manage what roles/users have access to that permission.
I have a few videos with demo projects using the Spatie Permission package: