I have a table like this:
|item_name |uom |qty |order_number
|bike |pc |1 |101
|ball |pc |2 |102
|bike |pc |5 |103
|car |pc |3 |106
|bike |pc |4 |108
|ball |pc |1 |109
|bike |pc |6 |115
|car |pc |1 |111
And I want to see in a view this data:
bike - 16 pcs overall:
101 - 1
103 - 5
108 - 4
115 - 6
ball - 3 pcs overall:
102 - 2
109 - 1
etc... I tried wuth this query, but I think it is not correct, because it gives me only name and sum of qty:
$saps = Item::where('year', 2019)->groupBy('item_name')->selectRaw('item_name, sum(qty) as sum')->get('item_name','sum');

item_nameandsum, that why you are getting only those two values.group byworks so in that sense it's correct. Maybe you need to use the collection group by method instead to get something closer to what you want