© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
4 replies
fsamapoor

How to access to the selected option in the SelectFilter?

I have provided options to a SelectFilter and everything works as expected. I have a special case where I need to modify the query if one specific option gets selected. How could I access to the selected option? Is it possible to modify the query based on the selected options?

SelectFilter::make('receiver')
  ->options(self::messageReceiver())
  ->searchable()
  ->attribute('chat_id')
SelectFilter::make('receiver')
  ->options(self::messageReceiver())
  ->searchable()
  ->attribute('chat_id')


I thought about chaining
when
when
method to the filter, but I just don't know how can I have access to the selected option so that I can replace the
true
true
part with the condition.

->when(true, function (BaseFilter $filter) {
  return $filter->modifyQueryUsing(function (Builder $query) {
    return $query->whereColumn('chat_id', 'sender_id');
  });
})
->when(true, function (BaseFilter $filter) {
  return $filter->modifyQueryUsing(function (Builder $query) {
    return $query->whereColumn('chat_id', 'sender_id');
  });
})
Solution
use
->query()
->query()


->query(function (Builder $query, array $data): Builder {
        return $query
            ->when(
                $data['created_until'],
                fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
            );
    })
->query(function (Builder $query, array $data): Builder {
        return $query
            ->when(
                $data['created_until'],
                fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
            );
    })
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

How to cutomize selected option label?
FilamentFFilament / ❓┊help
3y ago
Change the option title in a SelectFilter relationship
FilamentFFilament / ❓┊help
3y ago
How to access selected toggleable columns
FilamentFFilament / ❓┊help
3y ago
How to Access Selected Records in a BulkAction::visible() in Filament?
FilamentFFilament / ❓┊help
4mo ago