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

面包屑菜单 ​

HasRelationNavigator 需要一个带记录的页面:ViewRecord、EditRecord 以及使用 InteractsWithRecord 的页面已经具备它声明的两个方法 getRecord() 和 hasRecord()。在没有记录的页面上,PHP 会在类加载时立即报错。

记录页面当且仅当使用了 HasRelationNavigator 时才会出现在菜单中:查看页面、编辑页面或记录的任何自定义页面。在这些页面上,面包屑的最后一项会打开菜单。关联页面总会列出,排在记录页面之后,带有 relation manager 的图标和徽章,并且只在用户能看到时才显示。

如果页面已经自己构建面包屑,把它们传给 withRelationNavigator():

php
/**
 * @return array<string | int, string | Htmlable>
 */
public function getBreadcrumbs(): array
{
    return $this->withRelationNavigator([
        CustomerResource::getUrl('index') => 'Customers',
        $this->getBreadcrumb(),
    ]);
}

自己使用 InteractsWithRecord、而不是继承 ViewRecord 或 EditRecord 的自定义页面,会有两个 getBreadcrumbs() 方法。除非它定义了自己的版本,否则需要告诉 PHP 使用哪一个:

php
class CustomerActivity extends Page
{
    use HasRelationNavigator, InteractsWithRecord {
        HasRelationNavigator::getBreadcrumbs insteadof InteractsWithRecord;
        InteractsWithRecord::getBreadcrumbs as getRecordBreadcrumbs;
    }
}

菜单使用页面的 $navigationLabel 和 $navigationIcon,并且只在 canAccess() 对该记录允许时才显示该页面。

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