F
Filament10mo ago
Panda

How to delete [index] resource page?

I have a resource named SeriesResource for which I only want the view page as create and edit operations are handled via parent's ResourceManager. When I remove the index entry from the getPages of the resource, it throws the following error.
Route [filament.admin.resources.content.series.index] not defined.
Route [filament.admin.resources.content.series.index] not defined.
Following is the code for my SeriesResource
public static function getPages(): array
{
return [
// Commenting the index page throws an exception
// 'index' => Pages\ListSeries::route('/'),
// 'create' => Pages\CreateSeries::route('/create'),
'view' => Pages\ViewSeries::route('/{record}'),
// 'edit' => Pages\EditSeries::route('/{record}/edit'),
];
}
public static function getPages(): array
{
return [
// Commenting the index page throws an exception
// 'index' => Pages\ListSeries::route('/'),
// 'create' => Pages\CreateSeries::route('/create'),
'view' => Pages\ViewSeries::route('/{record}'),
// 'edit' => Pages\EditSeries::route('/{record}/edit'),
];
}
3 Replies
Chrispian
Chrispian10mo ago
In the context of the admin panel, I believe that page is required. But maybe you could redirect to the home page of your app (or other page) if anyone hits it?
Panda
Panda10mo ago
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] : []),
];
}
Chrispian
Chrispian10mo ago
Great find and thanks for following up with your solve!!