Difficulty creating a filter with a relationship using getTableFilters
Good afternoon everyone, how are you? I'm trying to make a filter between my instances and subscription table
Here is my relationship:
public function subscript()
{
return $this->belongsTo(Subscription::class, 'id', ['installable_id']);
}
getTableQuery and filter:
public function getTableQuery(): Builder
{
return Instance::where('business_id', Business::current()->id)->where('name', '!=', 'IA Instance');
}
public function getTableFilters(): array
{
return [
SelectFilter::make('subscript')
->options(SubscriptionStatus::options())
->label('Status')
->relationship('subscript', 'status'),
];
}
query obtained:
select
count(*) as aggregate
from
instances
Where
business_id = 1
and name != 'IA Instance'
and (
exists (
select
*
from
subscriptions
Where
instances.id = subscriptions.installable_id
and subscriptions.installable_id = 'active'
)
)
'active' would be one of the selectFilter options
problem:
Only the ending is wrong and should be:
and subscriptions.status = 'active'
what am I wrong?
Note: I'm using v2 of the filament
2 Replies
up
->relationship('subscript', 'status', fn (Builder $query) => $query->where(.....))