通过 Laravel Eloquent 加入、分组和计数
我有两个模型,卡片和风险
卡片有以下列:
1. id
2. weight
3. color //There are four types of colors, green, red, yellow, blue
风险有以下内容:
1. id
2. name
3. description
4. card_id
我想要实现的是对有多少风险的计数,按颜色分组,例如:
'color' => 'green'
'count' => '4'
'color' => 'blue'
'count' => '2'
'color' => 'red'
'count' => '6'
到目前为止我还无法做出这个查询使用 Eloquent,也许一些 DB::raw 可以帮助?
I have two Models, cards and risks
Cards has the following columns:
1. id
2. weight
3. color //There are four types of colors, green, red, yellow, blue
Risks has the following:
1. id
2. name
3. description
4. card_id
What I want to achieve is a count of how many risks are, grouped by colors, for example:
'color' => 'green'
'count' => '4'
'color' => 'blue'
'count' => '2'
'color' => 'red'
'count' => '6'
So far I haven't been able to make this query using Eloquent, maybe some DB::raw could help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)