gpt4 book ai didi

mysql - Eloquent 枢轴 : how to do select columns in Laravel 5. 1

转载 作者:行者123 更新时间:2023-11-29 21:04:33 25 4
gpt4 key购买 nike

我有两个模型 BillOrder,我可以通过以下方式获取订单记录:

    $orders = $bill->orders;

但我想像这样使用选择:

 $orders = $bill->orders->select([
'orders.*',
\DB::raw('sum(orders.quantity) as qty'),
\DB::raw('sum(orders.price) as total')
])
->groupBy('article_id');

我收到此错误:

Method select does not exist.

请大家帮帮我,谢谢!

最佳答案

我找到了解决方案:D

像这样编辑它:

 $orders = $bill->orders()->select([
'orders.*',
\DB::raw('sum(orders.quantity) as qty'),
\DB::raw('sum(orders.price) as total')
])
->groupBy('article_id')->get();

没关系:)))

关于mysql - Eloquent 枢轴 : how to do select columns in Laravel 5. 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36933610/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com