F
Filament11mo ago
Vp

How to give custom permission to sub-navigation relation manager

I create resource sub-navigation using https://filamentphp.com/docs/3.x/panels/resources/getting-started#resource-sub-navigation and also follow the demo https://demo.filamentphp.com/blog/posts/1 but I want to show/hide navigation button based on permission, I'm using Shield.
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\ViewList::class,
Pages\EditList::class,
Pages\ManageResult::class, // relation-manager (how can i apply `can('viewResult')` permission here
]);
}
public static function getRecordSubNavigation(Page $page): array
{
return $page->generateNavigationItems([
Pages\ViewList::class,
Pages\EditList::class,
Pages\ManageResult::class, // relation-manager (how can i apply `can('viewResult')` permission here
]);
}
If I just put inside table action then I can do like this and it's working
Tables\Actions\Action::make('result')
->url(function (Model $record) {
return ListResource::getUrl('result', [
'record' => $record->id,
]);
})
->visible(fn () => self::can('viewResult')), // this is working
Tables\Actions\Action::make('result')
->url(function (Model $record) {
return ListResource::getUrl('result', [
'record' => $record->id,
]);
})
->visible(fn () => self::can('viewResult')), // this is working
How can I apply (show/hide) result relation manager based on custom permission?
Solution:
I put below code on relation-manager page and it working ```php public static function shouldRegisterNavigation(array $parameters = []): bool { return auth()->user()->can('view_result_list');...
Jump to solution
1 Reply
Solution
Vp
Vp11mo ago
I put below code on relation-manager page and it working
public static function shouldRegisterNavigation(array $parameters = []): bool
{
return auth()->user()->can('view_result_list');
}
public static function shouldRegisterNavigation(array $parameters = []): bool
{
return auth()->user()->can('view_result_list');
}
Want results from more Discord servers?
Add your server