Assuming the following code to represent an order and the related transactions:
order
public function transactions(){
return $this->hasMany('App\Transaction');
}
already loaded collection ($orders)
order1
id
amount
transactions (relation)
txid
method
amount
order2
id
amount
transactions (relation)
txid
method
amount
The following filtering on already loaded collection does not work as expected:
$isNotEmpty = $orders->filter(function ($order) use ($receivingPayment) {
return $order->transactions->txid === $receivingPayment->txid && $order->transactions->method === $receivingPayment->method;
})->isNotEmpty();
It seems like the filtering on the relation transactions doesn't work this way?
It returns an empty element even if the transaction id is in the collection.