How to Add a Relationship to a Select in Filament
In this lesson, we will see how to add a relationship to a select in Filament.
Let's assume that we have a Post Model that belongs to a Category and we want to fill the select with the available categories.
Add a relationship to a select
To do that, you can use the code below.
The 'category' is the name of the relationship, and 'name' is the field to display.
Forms\Components\Select::make('category_id')
->required()
->relationship(
name: 'category',
titleAttribute: 'name'
),