我有两个模型,卡片和风险
卡片有下列栏:
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'到目前为止,我还无法使用雄辩的DB::raw来进行这个查询吗?
如能提供任何帮助,将不胜感激。
发布于 2022-02-25 01:45:08
Risk::select('card.name', DB::raw('count(risks.card_id)'))
->rightJoin('cards', 'card.id', '=', 'risks.card_id')
->groupBy('risks.card_id')
->get();https://stackoverflow.com/questions/71260113
复制相似问题