Show a NavigationItem to admins only

I use a closure to ensure some navigation items are visible to admins only:
NavigationItem::make('Admin')
->visible(fn() => auth()->user()->hasRole('super-admin'))
->url('/admin')
->icon('gmdi-settings-o'),
NavigationItem::make('Admin')
->visible(fn() => auth()->user()->hasRole('super-admin'))
->url('/admin')
->icon('gmdi-settings-o'),
Unfortunately this makes it impossible to use
php artisan route:cache
php artisan route:cache
. What would be a better way of doing this?
8 Replies
Patrick Boivin
Patrick Boivin13mo ago
What error are you getting with route:cache? I'm not sure I see the connection...
nielsdscrd
nielsdscrd13mo ago
Cannot assign Laravel\SerializableClosure\Serializers\Native to property Filament\Navigation\NavigationItem::$isVisible of type Closure|bool Replacing the closure with a simple true or false avoids the error.
Patrick Boivin
Patrick Boivin13mo ago
Where in your codebase are you building your nav items? Can you share a bit more code around it?
nielsdscrd
nielsdscrd13mo ago
I used this in a PanelProvider:
Patrick Boivin
Patrick Boivin13mo ago
Wow, can't even test this on my end... route:cache is crashing with a Segmentation fault 😦 Which version are you on specifically?
nielsdscrd
nielsdscrd13mo ago
v3.0.0-beta10. The segfault can be fixed with this: https://github.com/livewire/livewire/pull/6008 (My error also occurs without this fix. In my case I hit the error prior to the other segfault error occurring).
GitHub
[v3] Fix route caching by gehrisandro · Pull Request #6008 · livewi...
This PR fixes Laravel route caching. This problem has been mentioned in #5910 and #6000 Test implementation taken from here and sightly modified: #5910
nielsdscrd
nielsdscrd13mo ago
Re-tried with beta17 just now. Still the same.
Want results from more Discord servers?
Add your server