How to filter table results based on related table field?

Hello everyone. I have a table with orders, each order have payment [cash or credit card], I want to filter orders which have cash or credit card. Orders Model have relation to Payments Model:
public function payments(): HasOne
{
return $this->hasOne(RkPayments::class, 'VISIT', 'VISIT');
}
public function payments(): HasOne
{
return $this->hasOne(RkPayments::class, 'VISIT', 'VISIT');
}
Here is column in $table:
IconColumn::make('payments.PAYLINETYPE')
->icon(fn (string $state): string => match ($state) {
'1' => 'heroicon-o-credit-card',
'0' => 'heroicon-o-banknotes',
})->color(fn (string $state): string => match ($state) {
'0' => 'success',
'1' => 'warning',
default => 'gray',
})->label('Payment type'),
IconColumn::make('payments.PAYLINETYPE')
->icon(fn (string $state): string => match ($state) {
'1' => 'heroicon-o-credit-card',
'0' => 'heroicon-o-banknotes',
})->color(fn (string $state): string => match ($state) {
'0' => 'success',
'1' => 'warning',
default => 'gray',
})->label('Payment type'),
Here is filter:
SelectFilter::make('payType')->label('Payment type')->options([
'1' => 'Bank card',
'0' => 'Cash'
])->relationship('payments', 'PAYLINETYPE')->attribute('payments.PAYLINETYPE'),
SelectFilter::make('payType')->label('Payment type')->options([
'1' => 'Bank card',
'0' => 'Cash'
])->relationship('payments', 'PAYLINETYPE')->attribute('payments.PAYLINETYPE'),
When I use this filter, I get PHP error Our of memory. Can't get it clear, how to check what query it builds... Any ideas?
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server