F
Filament15mo ago
Panda

Is it possible to disable the resource index page?

I am working on a novel reading app where a novel can have many series and a series can have many chapters. I've structured my app in the following way. 1. The NovelResource has a relation manager with Series where I've only added a custom view action which redirects the user to filament.admin.resources.series.view route when clicked and passes the model ID as route parameter. 2. I've created a SeriesResource with only view and edit page and removed the create and index entries from the getPages function in SeriesResource. I've also hidden the resource from navigation by setting $shouldRegisterNavigation to false on the SeriesResource 3. When user is redirected to the series view page (filament.admin.resources.series.view) it throws an error saying the route filament.admin.resources.series.index is not defined. I do not want this page to be created or accessible by anyone because user will list the Series via NovelResource's SeriesRelationManager and cannot directly access the main page. 4. How can I completely disable the index route for SeriesResource? I know it uses the index page link in breadcrumb and the Cancel button but I want to change it to the parent novel page. Any help would be much appreciated.
3 Replies
Patrick Boivin
Patrick Boivin15mo ago
As you hinted, I think you'll need to adjust the breadcrumbs, and decide what to do with the main navigation. For the cancel button, you can override getCancelFormAction() on the page class.
Panda
PandaOP15mo ago
I solved the issue in my other using similar approach and I'll post it here as well. Fixed it! The index page URL is generated in the following places. 1. Sidebar navigation 2. Cancel button on edit page (not using edit page) 3. Breadcrumbs Since I'm not registering the resource in navigation the only thing that was giving me trouble was the breadcrumbs which after a deep dive into the Filament resource pages code I ended up overriding the getBreadcrumbs method on the ViewSeries page. I replaced the link to the index page with the view page of my parent/owner resource. This is my implementation in the SeriesResource/Pages/ViewSeries class.
/**
* {@inheritdoc}
*/
public function getBreadcrumbs(): array
{
// The parent model, loaded through the `novel` relationship
$baseUrl = route('filament.admin.resources.content.novels.view', [
'record' => $this->getRecord()->novel
]);

/**
* All procedure below is copied from the base `Page` class.
* @see \Filament\Resources\Pages\Page@getBreadcrumbs
*/
$resource = static::getResource();
$breadcrumb = $this->getBreadcrumb();

return [
$baseUrl => 'Novel',
$resource::getBreadcrumb(),
...(filled($breadcrumb) ? [$breadcrumb] : []),
];
}
/**
* {@inheritdoc}
*/
public function getBreadcrumbs(): array
{
// The parent model, loaded through the `novel` relationship
$baseUrl = route('filament.admin.resources.content.novels.view', [
'record' => $this->getRecord()->novel
]);

/**
* All procedure below is copied from the base `Page` class.
* @see \Filament\Resources\Pages\Page@getBreadcrumbs
*/
$resource = static::getResource();
$breadcrumb = $this->getBreadcrumb();

return [
$baseUrl => 'Novel',
$resource::getBreadcrumb(),
...(filled($breadcrumb) ? [$breadcrumb] : []),
];
}
Patrick Boivin
Patrick Boivin15mo ago
Nice
Want results from more Discord servers?
Add your server