Black Friday: coupon FRIDAY24 for 40% off Yearly/Lifetime membership! Read more here

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:
  • 67 courses (1172 lessons, total 43 h 18 min)
  • 90 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord

Recent New Courses