Skip to main content

Choosing the Right Tool

Filament offers multiple ways to manage relationships. Your choice depends on:
  • The type of relationship
  • The desired user experience
  • The complexity of related data
Best for: HasMany, HasManyThrough, BelongsToMany, MorphMany, MorphToManyInteractive tables below Edit/View pages for complete CRUD operations on related records.

Relation Managers

Relation managers display related records in a table underneath your resource form.

Creating a Relation Manager

Arguments:
  • CategoryResource - Parent resource class
  • posts - Relationship name
  • title - Attribute used to identify records
This creates CategoryResource/RelationManagers/PostsRelationManager.php:
packages/panels/src/Resources/RelationManagers/RelationManager.php

Registering Relation Managers

With custom URL parameter:

Relation Manager Variants

For BelongsToMany and MorphToMany relationships.
For HasMany and MorphMany relationships.
Adds restore, force delete, and trashed filter.
Adds a view modal for related records.

Working with Pivot Attributes

For many-to-many relationships with pivot data:

Displaying Pivot Columns

Editing Pivot Attributes

Ensure pivot attributes are listed in withPivot() on both the relationship and inverse relationship.

Attach and Detach

For BelongsToMany and MorphToMany relationships:

Attaching with Pivot Data

Scoping Attachable Records

Multiple Attachment

Preload Options

Search Multiple Columns

Associate and Dissociate

For HasMany and MorphMany relationships:
Associate actions work similarly to attach actions but update the foreign key instead of creating pivot records.

Accessing the Owner Record

Get the parent record in a relation manager:
In static methods, use callbacks:

Relation Manager Features

Read-Only Mode

On View pages, relation managers are read-only by default. Override this:
Or globally:

Customizing the Query

Grouping Relation Managers

Conditional Visibility

Combining with Form Content

Render relation managers as tabs alongside your form:
Customize the form tab:

Relation Pages

Alternative to relation managers using dedicated pages:
Register it:
Relation pages and relation managers serve the same purpose. Use pages when you want relationship management separate from the Edit/View page.

Sharing Resources with Relation Managers

Reuse resource definitions:

Hiding Shared Components

Hide fields/columns on the relation manager:

Performance Optimization

Lazy Loading

Relation managers lazy-load by default. Disable:

Eager Loading

Bulk Action Performance