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

页头、操作和 widget ​

关联页面可以在关联上方显示记录查看页面的一部分、页头操作和 widget。在 resource 上定义它们会作用于所有关联页面,在 relation manager 上定义则只作用于它自己的页面:

一个关联页面,订单上方有 widget、客户卡片和一个页头操作
php
public static function relationPageHeader(Schema $schema): Schema
{
    // 整个 infolist(static::infolist($schema))或其中一部分。
    return $schema->components([
        CustomerCard::make(),
    ]);
}

public static function getRelationPageHeaderActions(): array
{
    return [
        Action::make('email')
            ->url(fn (Customer $record): string => "mailto:{$record->email}"),
    ];
}

public static function getRelationPageHeaderWidgets(): array
{
    return [CustomerStats::class]; // 通过 $record 接收记录
}

public static function getRelationPageFooterWidgets(): array
{
    return [];
}
  • relation manager 的页头会替换 resource 的页头;两者的操作和 widget 都会显示,resource 的在前。
  • 页头操作作用于关联所属的记录。
  • 有页头时,记录名称不会在标题下方重复显示。
  • 只存在于查看页面类内部的东西(它自己的方法和模态框)在这里无法访问:请把它们移到 resource、action 类或 trait 中。

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