F
Filamentβ€’15mo ago
FranklySteve

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
FranklySteveOPβ€’15mo 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']);
})
Want results from more Discord servers?
Add your server