---
url: /filament-relation-navigator/guide/relation-pages.md
---
# Relation pages

### Opting in

Opt in on the resource, for every relation manager, or only on the relation
managers you want:

```php
use Wit3\FilamentRelationNavigator\Concerns\InteractsWithRelationPage;

class OrdersRelationManager extends RelationManager
{
    use InteractsWithRelationPage;
}
```

| Setup                                       | Relations with a page               |
| ------------------------------------------- | ----------------------------------- |
| `HasRelationPages` on the resource          | all, minus the ones that opt out    |
| `InteractsWithRelationPage` on a manager    | only the managers that opt in       |
| A page class you wrote (see below)          | all, minus the ones that opt out    |

To leave some relations out:

```php
// On the resource
public static function hasRelationPage(string $slug): bool
{
    return $slug !== 'notes';
}

// On a relation manager, with InteractsWithRelationPage
protected static bool $hasRelationPage = false;
```

A relation manager shared by two resources opts in for both: use the
resource's `hasRelationPage()` to leave one of them out.

### URLs and slugs

| `getRelations()` entry                          | URL                         |
| ----------------------------------------------- | --------------------------- |
| `'orders' => OrdersRelationManager::class`      | `/customers/1/orders`       |
| `SupportTicketsRelationManager::class` (no key) | `/customers/1/support-tickets` |
| `RelationGroup::make('Activity', [...])`        | `/customers/1/activity`     |

A relation manager's own slug wins
(`protected static ?string $relationPageSlug = 'tickets';`), then the key in
`getRelations()`, then the kebab-cased relationship name (or the group label:
give groups a key, since a translated label changes with the language). Slugs
equal to one of the resource's page keys (`edit`, `view`...) are skipped, and
so is a second relation with a slug already taken.

Each page is a named route, `relations.{slug}`:

```php
CustomerResource::getUrl('relations.orders', ['record' => $customer]);
```

### Authorization and behaviour

The relation manager receives the resource's **view** page as `$pageClass`
(the edit page when there is no view page), so `isReadOnly()`,
`canViewForRecord()`, `getBadge()` and every other check behave exactly as in
the tab. The view page is found by its key (`view`, `edit`, or
`$contextPage` on a page class you wrote) or by its class.

A relation page needs what the view page needs (its `canAccess()` and the
record's `view` policy; `update` when it stands for the edit page) and the
manager's `canViewForRecord()`. Without a view or an edit page, the `view`
policy applies. A policy that denies as not found gives a 404, an unknown
slug too. The menu, global search and "Open as page" only link the pages the
user can open.

Relation pages do not run the view page's own code: checks in its
`authorizeAccess()` or a `getRelationManagers()` filtered per user do not
apply there. Put them in policies, in `canViewForRecord()`, or veto a relation
page per record on the resource:

```php
public static function canAccessRelationPage(Model $record, string $slug): bool
{
    return $slug !== 'audit-logs' || auth()->user()->isAdmin();
}
```
