© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•2y ago•
6 replies
Pan

Searchable either name or barcode

What I am trying to do:
In my relationship manager, I have an action have a form field wherein I can type either the name or barcode of an equipment record and they show the same record with the same label, I want it to still display the name even if I searched the barcode

What I did:
I tried using this
https://filamentphp.com/docs/3.x/forms/fields/select#returning-custom-search-results
wherein I can indeed search by typing the barcode and it labels with the name
but I can't search by simply searching the name. Probably because the
Equipment::where('barcode')
Equipment::where('barcode')


I tried adding
where('barcode','name')
where('barcode','name')
but I get an error SQLSTATE[42000]: Syntax error

My issue/the error:
I am unaware if its possible to do search both columns in a single field and how to do that.
I am amateur when it comes to php


Code:
->getSearchResultsUsing(fn (string $search): array => Equipment::where('barcode', 'like', "%{$search}%")->limit(50)->pluck('name','id')->toArray())
                            ->getOptionLabelUsing(fn ($value): ?string => Equipment::find($value)?->barcode),
->getSearchResultsUsing(fn (string $search): array => Equipment::where('barcode', 'like', "%{$search}%")->limit(50)->pluck('name','id')->toArray())
                            ->getOptionLabelUsing(fn ($value): ?string => Equipment::find($value)?->barcode),
Select - Form Builder - Filament
Solution
Your initial approach was a good start, it was just missing the
orWhere
orWhere


This should search name and barcode, but only show name in the list.

->searchable()
->getSearchResultsUsing(fn (string $search): array => Equipment::query()
  ->where('name', 'like', "%{$search}%")
  ->orWhere('barcode', 'like', "%{$search}%")
  ->limit(50)
  ->pluck('name','id')
  ->toArray()
)
->searchable()
->getSearchResultsUsing(fn (string $search): array => Equipment::query()
  ->where('name', 'like', "%{$search}%")
  ->orWhere('barcode', 'like', "%{$search}%")
  ->limit(50)
  ->pluck('name','id')
  ->toArray()
)
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Searchable by pivot name
FilamentFFilament / ❓┊help
14mo ago
BelongsToMany TextColumn first_name last_name searchable
FilamentFFilament / ❓┊help
3y ago
Scan barcode repeater
FilamentFFilament / ❓┊help
15mo ago
->searchable()
FilamentFFilament / ❓┊help
13mo ago