リレーションページのカスタマイズ
1 つのリレーションのタイトル、サブ見出し、パンくずリスト
リレーションマネージャーは、ページクラスを使わずに、レコードをもとにして自分のページのこれらを設定できます。
php
class OrdersRelationManager extends RelationManager
{
public static function getRelationPageTitle(Model $ownerRecord): string|Htmlable|null
{
return "{$ownerRecord->name} の注文";
}
public static function getRelationPageSubheading(Model $ownerRecord): string|Htmlable|null
{
return '直近 12 か月';
}
public static function getRelationPageBreadcrumb(Model $ownerRecord): ?string
{
return '注文';
}
}デフォルトのままにするには null を返します。自分で書いたページクラス(後述)がある場合は、その $title、$subheading、$breadcrumb が優先されます。メニューとタブは、リレーションマネージャーのタイトルを使い続けます。リレーショングループにはリレーションマネージャーがないため、そのページはグループのラベルを使います。
独自のページクラス
自動生成されるリレーションページで、ほとんどの用途に対応できます。タイトルやパンくずリスト、その他 Filament のページでできることを変更したい場合は、ページクラスを自分で書いてください。そのリソースでは、パッケージがそのクラスを使います。
bash
php artisan make:filament-relation-navigator CustomerResourcephp
class CustomerRelationPage extends RelationPage
{
protected static string $resource = CustomerResource::class;
protected static ?array $relations = ['orders', 'invoices']; // これらだけ
protected static array $excludedRelations = ['notes']; // これらは除外
}php
public static function getPages(): array
{
return [
'index' => ListCustomers::route('/'),
'view' => ViewCustomer::route('/{record}'),
...CustomerRelationPage::relationRoutes(),
];
}このクラスは通常の Filament ページです。getTitle()、getBreadcrumbs()、getHeaderActions() をオーバーライドしたり、独自のトレイトを使ったりできます。