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('%'),

]),
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 . '%',...
Jump to solution
5 Replies
Solution
nostrodamned
nostrodamnedβ€’2y ago
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')
Tax::all()->map(function ($tax) {
return [
'value' => $tax->id,
'label' => $tax->name . ' - ' . $tax->rate . '%',
];
})->pluck('label', 'value')
Dan Harrin
Dan Harrinβ€’2y ago
there is a better way
Dan Harrin
Dan Harrinβ€’2y ago
virtual col, or getOptionLabelFromRecordUsing()
nostrodamned
nostrodamnedOPβ€’2y ago
@Dan Harrin yet again your genius is oustanding πŸ˜‰ TY
Want results from more Discord servers?
Add your server