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
Just don't register it? Simple
if
condition?I can't make the condition
Yeah cause an if condition can't be written into an array?
Write the if condition outside of the array
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
Please paste the whole function in here, I'll write it for you... Use triple backticks please:
```php
// your code
```
It’s a basic array that you need to add entries via a condition