Hide navigation

Filament::navigation(function (NavigationBuilder $builder): NavigationBuilder { return $builder ->groups([ NavigationGroup::make('Administration') ->if (condition: fn () => auth()->user()->name === 'ASACI') ->items([ NavigationItem::make('Users', 'users') ->label('Utilisateurs') ->icon('heroicon-o-user-group') ->isActiveWhen(fn () => request()->is('admin/users')) ->visible(fn() => auth()->user()->name === 'ASACI') ->url('/admin/users'), NavigationItem::make('log', 'log-viewer') ->label('Activités') ->icon('heroicon-o-clipboard-list') ->isActiveWhen(fn () => request()->is('admin/activities')) ->visible(fn() => auth()->user()->name === 'ASACI') ->url('/admin/activities'), ]), ]); }); Hello everyone, How to hide group browsing depending on the user logged in. Let's say the condition is based on his role. I really need help. Can anyone help me?
6 Replies
Dennis Koch
Dennis Koch2y ago
Just don't register it? Simple if condition?
Roomdada
RoomdadaOP2y ago
I can't make the condition
Quadrubo
Quadrubo2y ago
Yeah cause an if condition can't be written into an array? Write the if condition outside of the array
Roomdada
RoomdadaOP2y ago
if(auth()->user()->name === 'ASACI'){ NavigationGroup::make('Administration') ->items([ NavigationItem::make('Users', 'users') ->label('Utilisateurs') ->icon('heroicon-o-user-group') ->isActiveWhen(fn () => request()->is('admin/users')) ->visible(fn() => auth()->user()->name === 'ASACI') ->url('/admin/users'), NavigationItem::make('log', 'log-viewer') ->label('Activités') ->icon('heroicon-o-clipboard-list') ->isActiveWhen(fn () => request()->is('admin/activities')) ->visible(fn() => auth()->user()->name === 'ASACI') ->url('/admin/activities'), ]), } here's all the code maybe I missed something
Quadrubo
Quadrubo2y ago
Please paste the whole function in here, I'll write it for you... Use triple backticks please: ```php // your code ```
Dennis Koch
Dennis Koch2y ago
It’s a basic array that you need to add entries via a condition

Did you find this page helpful?