Skip to content

The breadcrumb menu ​

HasRelationNavigator needs a page with a record: ViewRecord, EditRecord and pages using InteractsWithRecord already have the two methods it declares, getRecord() and hasRecord(). On a page without a record PHP says so as soon as the class is loaded.

A record page is in the menu if, and only if, it uses HasRelationNavigator: the view page, the edit page or any custom page of the record. On those pages the last breadcrumb opens the menu. The relation pages are always listed, after the record pages, with the relation managers' icons and badges, and only when the user can see them.

If the page already builds its own breadcrumbs, pass them through withRelationNavigator():

php
public function getBreadcrumbs(): array
{
    return $this->withRelationNavigator([
        CustomerResource::getUrl('index') => 'Customers',
        $this->getBreadcrumb(),
    ]);
}

A custom page that uses InteractsWithRecord itself, instead of extending ViewRecord or EditRecord, has two getBreadcrumbs() methods. Unless it defines its own, tell PHP which one wins:

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

The menu uses the page's $navigationLabel and $navigationIcon, and shows it only when canAccess() allows it for the record.

Released under the MIT License.