パンくずリストのメニュー
HasRelationNavigator にはレコードを持つページが必要です。ViewRecord、EditRecord、InteractsWithRecord を使うページは、このトレイトが宣言する 2 つのメソッド getRecord() と hasRecord() をすでに持っています。レコードのないページでは、クラスが読み込まれた時点で PHP がエラーを出します。
レコードのページがメニューに載るのは、そのページが HasRelationNavigator を使っている場合だけです。対象は詳細ページ、編集ページ、またはレコードの任意のカスタムページです。それらのページでは、パンくずリストの最後の項目からメニューが開きます。リレーションページは常に、レコードのページの後に、リレーションマネージャーのアイコンとバッジ付きで並びます。ただし、ユーザーが閲覧できる場合に限ります。
ページがすでに独自のパンくずリストを組み立てている場合は、withRelationNavigator() に渡してください。
php
/**
* @return array<string | int, string | Htmlable>
*/
public function getBreadcrumbs(): array
{
return $this->withRelationNavigator([
CustomerResource::getUrl('index') => 'Customers',
$this->getBreadcrumb(),
]);
}ViewRecord や EditRecord を継承せずに自分で InteractsWithRecord を使うカスタムページには、getBreadcrumbs() メソッドが 2 つあります。独自に定義しない場合は、どちらを優先するかを PHP に指定してください。
php
class CustomerActivity extends Page
{
use HasRelationNavigator, InteractsWithRecord {
HasRelationNavigator::getBreadcrumbs insteadof InteractsWithRecord;
InteractsWithRecord::getBreadcrumbs as getRecordBreadcrumbs;
}
}メニューはページの $navigationLabel と $navigationIcon を使い、canAccess() がそのレコードに対して許可する場合にだけページを表示します。