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:
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')...
Jump to solution
3 Replies
Becker Maxime
Becker MaximeOP2y ago
Solution
Kenneth Sese
Kenneth Sese2y ago
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')
Becker Maxime
Becker MaximeOP2y ago
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
Want results from more Discord servers?
Add your server