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;
});
不要在函數中添加那么多參數,而是創(chuàng)建實例并根據條件添加查詢where()items
- 1 回答
- 0 關注
- 133 瀏覽
添加回答
舉報
