F
Filamentβ€’16mo ago
Mehmet K.

How can I add filtering by name field?

Filter::make('name')
->form([
Forms\Components\Select::make('name'),
])
->query(function (Builder $query, array $data): Builder {
$nameFilter = $data['name'];

if ($nameFilter) {
return $query->where('name', 'like', "%$nameFilter%");
}

return $query;
})
Filter::make('name')
->form([
Forms\Components\Select::make('name'),
])
->query(function (Builder $query, array $data): Builder {
$nameFilter = $data['name'];

if ($nameFilter) {
return $query->where('name', 'like', "%$nameFilter%");
}

return $query;
})
"I would like to perform filtering based on the 'name' field. However, in the Select input, I want to first list these options. Once an option is selected from the list, I want it to be used as a filter. The provided code didn't fulfill my needs accurately."
No description
2 Replies
LeandroFerreira
LeandroFerreiraβ€’16mo ago
Not sure
SelectFilter::make('name')
->multiple()
->options(YourModel::distinct()->pluck('name', 'name'))
SelectFilter::make('name')
->multiple()
->options(YourModel::distinct()->pluck('name', 'name'))
Mehmet K.
Mehmet K.OPβ€’16mo ago
Thank you it's work πŸ™‚
Want results from more Discord servers?
Add your server