SelectFilter search in multiple columns - Is this intended

Hello, I am working on a resource where i am looking into filtering and i found out that a SelectFilter can't searech in multiple columns. The clasic User having first_name and last_name Is this an intended functionality? As seen bellow, i replicated that functionality using a Filter with a Select inside but it looks like too much trouble for just a simple search in multiple columns Am i thinking of this the wrong way? Should we improve on the filter? What you thing?
Filter::make('custom_creator_id')
->form([
Select::make('creator_id')
->label('Agent 22')
->searchable(['first_name', 'last_name'])
->relationship('creator', 'first_name')
->getOptionLabelFromRecordUsing(fn(User $record) => $record->full_name),
])
->query(fn(Builder $query, array $data): Builder => $query
->when(
$data['creator_id'],
fn(Builder $query, $creatorId): Builder => $query->where('creator_id', $creatorId),
)),

SelectFilter::make('creator_id')
->label('Agent')
->searchable() // Here accept only a boolean or a Closure - the closure should return a boolean
->relationship('creator', 'first_name')
->getOptionLabelFromRecordUsing(fn(User $record) => $record->full_name),
Filter::make('custom_creator_id')
->form([
Select::make('creator_id')
->label('Agent 22')
->searchable(['first_name', 'last_name'])
->relationship('creator', 'first_name')
->getOptionLabelFromRecordUsing(fn(User $record) => $record->full_name),
])
->query(fn(Builder $query, array $data): Builder => $query
->when(
$data['creator_id'],
fn(Builder $query, $creatorId): Builder => $query->where('creator_id', $creatorId),
)),

SelectFilter::make('creator_id')
->label('Agent')
->searchable() // Here accept only a boolean or a Closure - the closure should return a boolean
->relationship('creator', 'first_name')
->getOptionLabelFromRecordUsing(fn(User $record) => $record->full_name),
Solution:
Not sure whether it's intended. I think it just wasn't needed yet, so nobody implemented it. General recommendation is to use a virtual column on your DB for full_name
Jump to solution
2 Replies
Solution
Dennis Koch
Dennis Koch8mo ago
Not sure whether it's intended. I think it just wasn't needed yet, so nobody implemented it. General recommendation is to use a virtual column on your DB for full_name
Eugen Pașca
Eugen PașcaOP8mo ago
Oh, yeah that is even better. Thanks
Want results from more Discord servers?
Add your server