Level 60
DB::table('table')
->select('item', DB::raw('count(*) as Total'))
->groupBy('item')
->get();
Model::groupBy('item')
->selectRaw('count(*) as Total, item')
->get();
Does some this this example work?)
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello guys, i have a record on my database something like this
--------------------
Name|Count
--------------------
Item 1 | 5
Item 2 | 10
Item 3 | 4
Item 1 |4
Item 3 | 5
--------------------
now what i want to do with my query is this
Item 1 - 9
Item 2 - 10
Item 3 - 9
can anyone help me please?.
Try to use sum() instead of count()
DB::table('table')
->select('item', DB::raw('sum(count) as Total'))
->groupBy('item')
->get();
Please or to participate in this conversation.