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?
2 Replies
Dan Harrin
Dan Harrin2y ago
I think this is quite hard for us to debug without looking at your database or relationship structure this should definitely work, something must just be slightly wrong in your code
rajul
rajulOP2y ago
Thanks, it is working now, may be some cache issue.
Want results from more Discord servers?
Add your server