1 回答

TA贡献1835条经验 获得超7个赞
我不知道这个条件,但你可以简单地试试这个->where(function ($qu) use ($filter))
$sum = $pipes->sum(function ($pipe) use ($filter) {
$total = 0;
$itemsQ = $pipe->items
->where('status', 'Terminé')
->where('closed', false);
if($filter == false) {
$items = $itemsQ->where('payment_id', 'exists', false)
->where('closed', false)
->where('locker', 'exists', false)->get();
}else {
$items = $itemsQ->where('payment_id', 'exists', true)
->where('closed', false)
->where('locker', 'exists', false)
->where('failed_to_pay', true)->get();
}
foreach ($items as $item) {
$total = $total + ($item->price * $item->quantity);
}
return $total;
});
不要在函数中添加那么多参数,而是创建实例并根据条件添加查询where()items
- 1 回答
- 0 关注
- 129 浏览
添加回答
举报