我向我建议了此代码。我正在尝试总结stock_in_qty和stock_out_qty。
$warehouse1stocks = Warehouse1stocks::select(
"order_item_id",
Warehouse1stocks::raw('SUM(stock_in_qty) as stock_in_qty'),
Warehouse1stocks::raw('SUM(stock_out_qty) as stock_out_qty'))->groupBy('order_item_id')->get();
// dd($warehouse1stocks);
return view("warehouse1.index", compact("warehouse1stocks", $warehouse1stocks));
我的问题是这个错误
我试图从这里的其他问题中寻找答案,我认为我的代码似乎还可以,但是为什么我仍然遇到该错误?
您认为我的代码有什么问题?预先感谢!
答案 0 :(得分:3)
代替写作:
UITableView
写:
Warehouse1stocks::raw('SUM(stock_in_qty) as stock_in_qty')
定义写表达式时
答案 1 :(得分:1)
使用这个
$warehouse1stocks = Warehouse1stocks::select(
"order_item_id",
\DB::raw('SUM(stock_in_qty) as stock_in_qty'),
\DB::raw('SUM(stock_out_qty) as stock_out_qty'))->groupBy('order_item_id')->get();
// dd($warehouse1stocks);
return view("warehouse1.index", compact("warehouse1stocks", $warehouse1stocks));