F
Filament2mo ago
nowak

Show navigation and topbar conditionally

In my panel provider I am disabling the navigation and topbar like this:
->navigation(false)
->topbar(false)
->navigation(false)
->topbar(false)
Since I actually only want to do this for specific roles, I wonder if there is a way to set this conditionally? This does not seem to be working:
->navigation(fn() => auth()->user()->hasRole('super_admin'))
->navigation(fn() => auth()->user()->hasRole('super_admin'))
7 Replies
Andrew Wallo
Andrew Wallo2mo ago
You can maybe try doing it in a listener.
nowak
nowakOP2mo ago
Hmm.. I am not sure how to use listeners for this in filament
Andrew Wallo
Andrew Wallo2mo ago
I think filament has some events that are sent when the panel is booted or something
nowak
nowakOP2mo ago
Do you mean the render hooks?
Andrew Wallo
Andrew Wallo2mo ago
GitHub
filament/packages/panels/src/Events at 3.x · filamentphp/filament
A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS. - filamentphp/filament
Andrew Wallo
Andrew Wallo2mo ago
Those events You can even dispatch a custom event inside a middleware
awcodes
awcodes2mo ago
Panels require either the default navigation or the top navigation. Of which you control the visibility of resources/items via policies. If you don’t want either then you need a custom layout. Which is going to be more trouble than it’s probably worth, but it can be done.
Want results from more Discord servers?
Add your server