F
Filament14mo ago
jaocero

[SOLVE] getSearchResultsUsing turns to id number if I use multiple()

Whenever I try to search for the first time the email it works but the problem comes after I will select another email. As you can see in the image, instead of email name it turns into the id of the email which is weird. Does my code incorrect?
->form([
Forms\Components\Select::make('invited_id')
->required()
->multiple()
->searchable()
->getSearchResultsUsing(function (string $search) {
return User::where('email', 'like', "%{$search}%")
->where('email', '!=', auth()->user()->email)
->whereHas('roles', function ($query) {
$query->where('name', 'admin');
})
->limit(50)
->pluck('email', 'id');
})
->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->email)
->placeholder('Search by email')
->helperText(new HtmlString("Only registered users will be displayed here, and you can only invite up to three members.<br><span style='color:#F87171'><strong>Note:</strong><i> Please note that it is not possible to invite members who have already been invited to another team.</i></span> "))
->maxItems(3)
])
->form([
Forms\Components\Select::make('invited_id')
->required()
->multiple()
->searchable()
->getSearchResultsUsing(function (string $search) {
return User::where('email', 'like', "%{$search}%")
->where('email', '!=', auth()->user()->email)
->whereHas('roles', function ($query) {
$query->where('name', 'admin');
})
->limit(50)
->pluck('email', 'id');
})
->getOptionLabelUsing(fn ($value): ?string => User::find($value)?->email)
->placeholder('Search by email')
->helperText(new HtmlString("Only registered users will be displayed here, and you can only invite up to three members.<br><span style='color:#F87171'><strong>Note:</strong><i> Please note that it is not possible to invite members who have already been invited to another team.</i></span> "))
->maxItems(3)
])
1 Reply
jaocero
jaocero14mo ago
I solved it as I read other questions here. Here is my code for someone also facing this problem:
->getOptionLabelsUsing(fn ($values): array => User::find($values)?->pluck('email', 'id')->toArray())
->getOptionLabelsUsing(fn ($values): array => User::find($values)?->pluck('email', 'id')->toArray())