Skip to content
本页为翻译版本:如有出入,以英文文档为准。 阅读英文版

自定义关联页面 ​

单个关联的标题、副标题和面包屑 ​

relation manager 可以根据记录为自己的页面设置这些内容,无需页面类:

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 优先。菜单和标签页仍使用 relation manager 的标题。关联分组没有 relation manager,所以它们的页面使用分组标签。

自己编写页面类 ​

自动生成的关联页面能满足大多数需求。如果要修改它们的标题、面包屑,或者做 Filament 页面能做的其他任何事情,可以自己编写页面类;本包会对该 resource 使用你的类:

bash
php artisan make:filament-relation-navigator CustomerResource
php
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(),使用你自己的 trait,等等。

版本 1.8.1,发布于 2026-11-15 · MIT 许可证。