猿问

Laravel 雄辩的参数太少,函数 1 已通过,2 在我的查询中预期

这是我的代码:


 $sum = $pipes->sum(function ($pipe) use ($filter) {

            $total = 0;

            $items = $pipe->items

                ->where('status', 'Terminé')

                ->where('closed', false)

                ->where(function ($qu) use ($filter) {

                    if ($filter === false) {

                        $qu->where('payment_id', 'exists', false)

                            ->where('closed', false)

                            ->where('locker', 'exists', false);

                    } else {

                        $qu->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;

        });

错误是关于->get();


有人有解决问题的想法吗?谢谢!


HUWWW
浏览 130回答 1
1回答

qq_花开花谢_0

我不知道这个条件,但你可以简单地试试这个->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
随时随地看视频慕课网APP
我要回答