Select Search Optimization

Looking for a second set of eyes here. Trying to get good UX here. Participants list can in the thousands, but search seems a bit slow here and obviously nothing is loaded by default. Suggestions for improvements?
Select::make('participant_id')
->label('Participant')
->placeholder('Select a participant (optional)')
->searchable()
->getSearchResultsUsing(function (string $search) {
$query = User::active()->whereHas('participant');

if (auth()->user()->isCaseManager()) {
$query->where('participant.agency_id', auth()->user()->case_manager->agency_id);
}

return $query
->where('name', 'like', "%{$search}%")
->limit(50)
->get()
->pluck('name', 'participant.id')
->toArray();
})
->afterStateUpdated(function (Get $get, Set $set) {
// does some stuff
})
->reactive(),
Select::make('participant_id')
->label('Participant')
->placeholder('Select a participant (optional)')
->searchable()
->getSearchResultsUsing(function (string $search) {
$query = User::active()->whereHas('participant');

if (auth()->user()->isCaseManager()) {
$query->where('participant.agency_id', auth()->user()->case_manager->agency_id);
}

return $query
->where('name', 'like', "%{$search}%")
->limit(50)
->get()
->pluck('name', 'participant.id')
->toArray();
})
->afterStateUpdated(function (Get $get, Set $set) {
// does some stuff
})
->reactive(),
. Basically a participant is relationship on a user. The name is tied to the user, but i need the participant id. Im sure it can be done in a cleaner way. Im open to all ideas.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server