Filament: Select Dropdown Search with Custom Logic

You can customize the Select dropdown to search for any custom logic you want with the ->getSearchResultsUsing() method.

This example shows how to search for a Customer by email/phone/name after whatever the user is typing in the Select search box.

Forms\Components\Select::make('user_id')
->label('Customer')
->getSearchResultsUsing(function (string $search): array {
return User::query()
->where(function (Builder $builder) use ($search) {
$searchString = "%$search%";
$builder->where('name', 'like', $searchString)
->orWhere('email', 'like', $searchString)
->orWhere('phone', 'like', $searchString);
})
->where('role_id', Role::CUSTOMER)
->limit(50)
->get()
->mapWithKeys(function (User $customer) {
return [$customer->id => $customer->name];
})
->toArray();
})

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 59 courses (1057 lessons, total 42 h 44 min)
  • 79 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent Premium Tutorials