Searchable select returning invalid results

As title, when I setup a simple Select component like below, it is returning results that do not match the query string? Select::make('customer_id') ->options(Customer::all()->sortBy('name')->pluck('name', 'id')) ->searchable(['name'])->required(), Is there something I am missing here?
2 Replies
Miguel García
It might be a bug or maybe it is the default behaviour, I'm not sure, but in the mean time if you need to fix it you can use your own search function
Forms\Components\Select::make('customer_id')
->getSearchResultsUsing(fn (string $search): array =>
Customer::where('name', 'like', "%{$search}%")
->limit(5)
->pluck('name', 'id')
->toArray()
)
->native(false)
->options(Customer::all()
->pluck('name', 'id')
->toArray()
)
->optionsLimit(5)
->preload()
->required()
->searchable()
Forms\Components\Select::make('customer_id')
->getSearchResultsUsing(fn (string $search): array =>
Customer::where('name', 'like', "%{$search}%")
->limit(5)
->pluck('name', 'id')
->toArray()
)
->native(false)
->options(Customer::all()
->pluck('name', 'id')
->toArray()
)
->optionsLimit(5)
->preload()
->required()
->searchable()
digoots
digoots3w ago
Yeah I can get it to work with a search query, its just less responsive, my original way just loads all the values at once then searches without any network requests
Want results from more Discord servers?
Add your server