Select multiple getSearchResultsUsing()
Hello, I have a problem when searching on a multiple select when I run it, it changes the intutile of the options by the ids and not the names.
Select::make('skills')->required()->multiple()->searchable()->getSearchResultsUsing(fn(string $search) => AlternativeOccupation::where('name', 'like', "{$search}%")->limit(50)->pluck('name', 'id'))->getOptionLabelUsing(fn($value): ?string => AlternativeOccupation::find($value)?->name),
Solution:Jump to solution
Since you’re using multiple you need to use
getOptionLabelsUsing
with a “s” on Labels. You’ll need to change your closure as well to handle the array:
->getOptionLabelsUsing(fn ($values): array => YourModel::find($values)?->pluck('name', 'id')
...3 Replies
Solution
Since you’re using multiple you need to use
getOptionLabelsUsing
with a “s” on Labels. You’ll need to change your closure as well to handle the array:
->getOptionLabelsUsing(fn ($values): array => YourModel::find($values)?->pluck('name', 'id')
oh thanks to you I found it, I added a toArray() at the end otherwise I would have had an error saying I was returning a collection