Help using a filter on table with relationship and PHP Enum please?

Hi, I'm trying to create a filter in a table using a relationship that uses a PHP enum for it's options. I've so far got got the following, but it has no effect on the displayed data. Any pointers please? Thanks
SelectFilter::make('invoice.paid_status')
->relationship('invoice', 'paid_status')
->options(PaidStatus::class)
->attribute(PaidStatus::class),
SelectFilter::make('invoice.paid_status')
->relationship('invoice', 'paid_status')
->options(PaidStatus::class)
->attribute(PaidStatus::class),
1 Reply
FranklySteve
FranklySteveOP16mo ago
Ok, I think I solved it. It's all I've worked on since asking, (it's good to learn) although what I've done doesn't feel completely correct, but maybe it's right! Either way it works. 😂
SelectFilter::make('paid_status')
->options(PaidStatus::class)
->query(function (Builder $query, array $data): Builder {
if (empty($data['value'])) {
return $query
->whereRelation('invoice', 'paid_status', '!=' , null );
}
return $query
->whereRelation('invoice', 'paid_status', $data['value']);
})
SelectFilter::make('paid_status')
->options(PaidStatus::class)
->query(function (Builder $query, array $data): Builder {
if (empty($data['value'])) {
return $query
->whereRelation('invoice', 'paid_status', '!=' , null );
}
return $query
->whereRelation('invoice', 'paid_status', $data['value']);
})

Did you find this page helpful?