【发布时间】:2021-08-30 08:59:54
【问题描述】:
假设下面的代码代表一个订单和相关的交易:
订购
public function transactions(){
return $this->hasMany('App\Transaction');
}
已加载集合 ($orders)
order1
id
amount
transactions (relation)
txid
method
amount
order2
id
amount
transactions (relation)
txid
method
amount
对已加载集合的以下过滤无法按预期工作:
$isNotEmpty = $orders->filter(function ($order) use ($receivingPayment) {
return $order->transactions->txid === $receivingPayment->txid && $order->transactions->method === $receivingPayment->method;
})->isNotEmpty();
似乎对关系 transactions 的过滤不起作用?
即使事务 id 在集合中,它也会返回一个空元素。
【问题讨论】:
标签: php laravel collections