Select using getSearchResultsUsing with preload

Hi i follow this Tricks :
https://v2.filamentphp.com/tricks/render-html-in-select-options
https://v2.filamentphp.com/tricks/render-html-in-select-options
I try use getSearchResultsUsing and getOptionLabelUsing. I want use preload too, but it's not working. If i use options and getOptionlabelUsing, preload works but searchable not. (when i use this, i comment ->where)
Select::make('product')->label('Eventos')
//->options(function(){
->getSearchResultsUsing( function(string $search) {
$user = auth()->user();

if($user->products()->whereBelongsTo(Filament::getTenant())->whereRelation('performances','start','>=',now()->subMonths(8))->count() > 0)
{
$products =
$user->products()->whereBelongsTo(Filament::getTenant())
->whereRelation('performances','start','>=',now()->subMonths(8))
->where('internal_name','like',"%{$search}%")
->get();
}else{
$products =
Product::whereBelongsTo(Filament::getTenant())
->whereRelation('performances','start','>=',now()->subMonths(8))
->where('internal_name','like',"%{$search}%")
->get();
}
return $products->mapWithKeys(function ($product) {
return [$product->stx_id => static::getCleanOptionString($product)];
})->toArray();

})
->getOptionLabelUsing(function ($value): string {
$product = Product::find($value);

return static::getCleanOptionString($product);
})
->preload()
->allowHtml()
->searchable()
Select::make('product')->label('Eventos')
//->options(function(){
->getSearchResultsUsing( function(string $search) {
$user = auth()->user();

if($user->products()->whereBelongsTo(Filament::getTenant())->whereRelation('performances','start','>=',now()->subMonths(8))->count() > 0)
{
$products =
$user->products()->whereBelongsTo(Filament::getTenant())
->whereRelation('performances','start','>=',now()->subMonths(8))
->where('internal_name','like',"%{$search}%")
->get();
}else{
$products =
Product::whereBelongsTo(Filament::getTenant())
->whereRelation('performances','start','>=',now()->subMonths(8))
->where('internal_name','like',"%{$search}%")
->get();
}
return $products->mapWithKeys(function ($product) {
return [$product->stx_id => static::getCleanOptionString($product)];
})->toArray();

})
->getOptionLabelUsing(function ($value): string {
$product = Product::find($value);

return static::getCleanOptionString($product);
})
->preload()
->allowHtml()
->searchable()
1 Reply
marianov24
marianov24OP8mo ago
OK, I found a solution, use ->options and ->getSearchResultsUsing together. I don't know if this is the best solution. Can anyone confirm this?
Want results from more Discord servers?
Add your server