F
Filamentβ€’3y ago
mcdc

Restrict user to view certain Navigation Group

How to restrict other user/acc with type user from viewing NavigationGroup::make('Admin') and only user with type admin https://filamentphp.com/docs/2.x/admin/navigation#advanced-navigation-customization
Filament::navigation(function (NavigationBuilder $builder): NavigationBuilder {
return $builder
->groups([

NavigationGroup::make(null)
->items([
NavigationItem::make('Dashboard')
->url(route('filament.pages.dashboard'))
->icon('tabler-chart-treemap'),
NavigationItem::make('Timer')
->url('/app/users/timer')
->icon('tabler-clock-hour-3')
->sort(2)
]),

NavigationGroup::make('Admin')
->items([
NavigationItem::make('Users')
->url('/app/users')
->icon('heroicon-o-user-group')
->sort(1),

NavigationItem::make('Roles')
->url('/app/shield/roles')
->icon('heroicon-o-shield-check')
->sort(2),

NavigationItem::make('Task')
->url('/app/tasks')
->icon('tabler-subtask')
->sort(3),
]),
...,
...,
]);
});
Filament::navigation(function (NavigationBuilder $builder): NavigationBuilder {
return $builder
->groups([

NavigationGroup::make(null)
->items([
NavigationItem::make('Dashboard')
->url(route('filament.pages.dashboard'))
->icon('tabler-chart-treemap'),
NavigationItem::make('Timer')
->url('/app/users/timer')
->icon('tabler-clock-hour-3')
->sort(2)
]),

NavigationGroup::make('Admin')
->items([
NavigationItem::make('Users')
->url('/app/users')
->icon('heroicon-o-user-group')
->sort(1),

NavigationItem::make('Roles')
->url('/app/shield/roles')
->icon('heroicon-o-shield-check')
->sort(2),

NavigationItem::make('Task')
->url('/app/tasks')
->icon('tabler-subtask')
->sort(3),
]),
...,
...,
]);
});
Filament
Navigation - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
9 Replies
Dan Harrin
Dan Harrinβ€’3y ago
if a user cant see any items within a group, a group wont show
mcdc
mcdcOPβ€’3y ago
I mean if the user has a type of "admin" i wan to show all navigation group, but if user has type of regular or just user i want to hide certain navigation group So i want to hide this NavigationGroup::make('Admin') to regular user
Dan Harrin
Dan Harrinβ€’3y ago
you hide all items within it
toeknee
toekneeβ€’3y ago
Via policies πŸ™‚
MrHex
MrHexβ€’3y ago
Policies are extremely good!
mcdc
mcdcOPβ€’3y ago
Thanks, can you redirect me to the documentation, I dont know how to start. I do have this RolePolicy by Shield Roles
mcdc
mcdcOPβ€’3y ago
Thanks I just discover, by using https://github.com/bezhanSalleh/filament-shield I can just use, to restrict or redirect user without type super_admin
use HasPageShield;

protected function getShieldRedirectPath(): string {
return '/'; // redirect to the root index...
}
use HasPageShield;

protected function getShieldRedirectPath(): string {
return '/'; // redirect to the root index...
}
GitHub
GitHub - bezhanSalleh/filament-shield: The easiest and most intuiti...
The easiest and most intuitive way to add access management to your Filament Admin Resources, Pages & Widgets through spatie/laravel-permission - GitHub - bezhanSalleh/filament-shield: Th...
black ka1ser
black ka1serβ€’2y ago
this usage is in resource page?

Did you find this page helpful?