FilamentF
Filamentβ€’3y ago
Bleak

concatenate fields on a select options

I am trying and to concatenate the name and rate fields for a select options
I tried
->getOptionLabelUsing(fn ($value): ?string => Tax::find($value)?->name. ' - '. Tax::find($value)?->rate. '%')
which doesnt work
any clues please πŸ™‚
                Select::make('taxes')
                    ->required()
                    ->relationship('taxes', 'name')
                    ->options(
                        Tax::pluck('name', 'id')


                    )
                    ->getOptionLabelUsing(fn ($value): ?string => Tax::find($value)?->name. ' - '. Tax::find($value)?->rate. '%')

                    ->preload()
                    ->createOptionForm([
                        Forms\Components\TextInput::make('name'),
                        Forms\Components\TextInput::make('rate')->suffix('%'),

                    ]),
Solution
got it for anyone else in the future
 Tax::all()->map(function ($tax) {
                            return [
                                'value' => $tax->id,
                                'label' => $tax->name . ' - ' . $tax->rate . '%',
                            ];
                        })->pluck('label', 'value')
Was this page helpful?