Form Select - Relationship customise display?

I'd like to customise the name of a relationship via i.e. instead of id, name. I'd like: id, concat(name, '-', id) Is there a way to do this?
4 Replies
Patrick Boivin
Maybe something like this
Select::make('category_id')
->relationship('category', 'name_id', function (Builder $query) {
return $query->select(DB::raw('`id`, `name`, concat(`name`, "-", `id`) as `name_id`'));
})
Select::make('category_id')
->relationship('category', 'name_id', function (Builder $query) {
return $query->select(DB::raw('`id`, `name`, concat(`name`, "-", `id`) as `name_id`'));
})
toeknee
toekneeOP2y ago
Ahh perfect! I always forget about these hidden closures
Ander
Ander17mo ago
@toeknee_iom
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->name} - {$record->id}")
->getOptionLabelFromRecordUsing(fn (Model $record) => "{$record->name} - {$record->id}")
Ander
Ander17mo ago
Filament
Fields - Form Builder - Filament
The elegant TALL stack form builder for Laravel artisans.
Want results from more Discord servers?
Add your server