menu item depending on user role or permission
How can i set a menu item only, if the user has a specific role?
I tried https://filamentphp.com/tricks/conditions-on-user-menu-items-based-on-roles
But cant get it running.
I installed in config/filament.php
`
I created
I have a Page in app/Filament/Pages/GitLog.php with
What to i have to put in app/Http/Middleware/UserMenuItemMiddleware.php please?
I want to show the page GitLog.php only when the user has role "Root".
Filament
Conditions on user menu items based on roles by sheldon - Tricks - ...
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
8 Replies
Sorry, I'm not sure I understand the need for a middleware... I think you could just do this in
AppServiceProvider
boot()
:
Thanks @pboivin I changed it.
What do i have to place please inside Filament::registerUserMenuItems
My Page i want to show only for user role "xx" is app/Filament/Pages/GitLog.php
Or better said the MenuItem i want to show.
Probably something like
->url(GitLog::getUrl())
if (Auth::user()->hasRole('Root')) {
returns error: Call to a member function hasRole() on null.
the workaround trick is done because of this it seems: https://filamentphp.com/tricks/conditions-on-user-menu-items-based-on-roles
Filament
Conditions on user menu items based on roles by sheldon - Tricks - ...
Filament is a collection of tools for rapidly building beautiful TALL stack apps, designed for humans.
Try
Auth::user()?->hasRole('Root')
now there is no error 🙂
but my problem is that the menu item i try to load does not appear in the dashboard menu. Nore if the user has roel Root or Admin.
I have in AppServiceProvider:
and in app/Filament/Pages/GitLog.php
but the menu item will not show up. for no user role.
What is my mistake please?
I found it out!
I thought UserMenuItems is in the Dashboard menu 🙈
Now is see its the "user"menu. UFFF
I want to register in the Dashboard menu on the left side. Is that registerNavigationItems?
yes
Thanks very much for all your great help. @Dan Harrin and @pboivin now it is working perfect!
Filament is really great! Regards from Madrid.