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']));
                }),

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?
Was this page helpful?