Managing relationships
Choosing the right tool for the job
Filament provides many ways to manage relationships in the app. Which feature you should use depends on the type of relationship you are managing, and which UI you are looking for.
Relation managers - interactive tables underneath your resource forms
These are compatible with
HasMany
,HasManyThrough
,BelongsToMany
,MorphMany
andMorphToMany
relationships.
Relation managers are interactive tables that allow administrators to list, create, attach, associate, edit, detach, dissociate and delete related records without leaving the resource's Edit or View page.
Select & checkbox list - choose from existing records or create a new one
These are compatible with
BelongsTo
,MorphTo
andBelongsToMany
relationships.
Using a select, users will be able to choose from a list of existing records. You may also add a button that allows you to create a new record inside a modal, without leaving the page.
When using a BelongsToMany
relationship with a select, you'll be able to select multiple options, not just one. Records will be automatically added to your pivot table when you submit the form. If you wish, you can swap out the multi-select dropdown with a simple checkbox list. Both components work in the same way.
Repeaters - CRUD multiple related records inside the owner's form
These are compatible with
HasMany
andMorphMany
relationships.
Repeaters are standard form components, which can render a repeatable set of fields infinitely. They can be hooked up to a relationship, so records are automatically read, created, updated, and deleted from the related table. They live inside the main form schema, and can be used inside resource pages, as well as nesting within action modals.
From a UX perspective, this solution is only suitable if your related model only has a few fields. Otherwise, the form can get very long.