F
Filamentβ€’2y ago
benshawuk

Can I use relationships in a form like this?

I have a table that successfully uses a relationship from another table: Tables\Columns\TextColumn::make('company.company_name'), This displays the company name due to the relation setup in the model. But when I try and replicate this for the form, it doesn't work: Forms\Components\Select::make('company.company_name') ->required() How do I get the select drop down to show the company names? (and write the ID back to the database when editing the records)?
3 Replies
Patrick Boivin
Patrick Boivinβ€’2y ago
Not sure if there's a better solution but I think I've always manually specified the options in my selects, something like this:
Select::make('manufacturer_id')
->label(__('Manufacturer'))
->options(
Manufacturer::whereType(ManufacturerType::TIRE)
->orderBy('name', 'asc')
->pluck('name', 'id')
)
Select::make('manufacturer_id')
->label(__('Manufacturer'))
->options(
Manufacturer::whereType(ManufacturerType::TIRE)
->orderBy('name', 'asc')
->pluck('name', 'id')
)
benshawuk
benshawukOPβ€’2y ago
Thanks guys! Really appreciate the help here whilst I’m getting up to speed on Filament. πŸ™‚πŸ‘
Want results from more Discord servers?
Add your server