从雄辩关系中获取价格总和

发布于 2025-02-13 22:14:20 字数 257 浏览 1 评论 0原文

有没有更快的方法在雄辩中进行以下操作,我尝试了工作,但在我的情况下无法实施它

 $bCollection=B::where(['user_id' => $user])->get();
            foreach($bCollectionas $b){
                $total+=$b->b_by_a($condition)->first()['counter'];
            }

Is there a quicker way to do the following in eloquent, I tried withSum but couldn't implement it in my case

 $bCollection=B::where(['user_id' => $user])->get();
            foreach($bCollectionas $b){
                $total+=$b->b_by_a($condition)->first()['counter'];
            }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

赴月观长安 2025-02-20 22:14:22

问题不清楚。

如果您想获得一些有关系的表格,则需要尝试这样的事情:

$model->relation()->sum('column')

The question is not clear.

If you want to get sum of some table which has relation, then you need to try something like this:

$model->relation()->sum('column')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文