© 2026 Hedgehog Software, LLC

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

custom filter on foreign table not working

I have user table having gender and one foreign table with 'metadata_id" key which points to metadata.
metadata contains category
I created filter like this in UserResource.
SelectFilter::make('gender')->
                    options([
                        'f' => 'Female',
                        'm' => 'Male',
                    ])->
                    attribute('gender'),
SelectFilter::make('category')
                ->options([
                        0 => 'Normal'
                        1 => 'Pro',
                        2 => 'Premium',
                    ])
                ->query(function (Builder $query, array $data) {
                    if (!empty($data['value']))
                        $query->whereHas('metadata', 
                            fn(Builder $query) => $query->where('category', '=', $data['value']));
                }),
SelectFilter::make('gender')->
                    options([
                        'f' => 'Female',
                        'm' => 'Male',
                    ])->
                    attribute('gender'),
SelectFilter::make('category')
                ->options([
                        0 => 'Normal'
                        1 => 'Pro',
                        2 => 'Premium',
                    ])
                ->query(function (Builder $query, array $data) {
                    if (!empty($data['value']))
                        $query->whereHas('metadata', 
                            fn(Builder $query) => $query->where('category', '=', $data['value']));
                }),

If I select only category filter then it is working fine but If I select both gender and category filter, no users get return in table.
I have confirmeed that there is data in my table to have few common users for both filters.

Am I doing something wrong here?
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Custom Table Filter
FilamentFFilament / ❓┊help
5mo ago
Custom Filter Table
FilamentFFilament / ❓┊help
3y ago
Table custom filter validate
FilamentFFilament / ❓┊help
2y ago
Not able to filter table on custom livewire component
FilamentFFilament / ❓┊help
2y ago