php - Laravel Sum value and group by
I have some issue, im using Laravel with DB table, i need to sum values, also display name (text field) and group by content id, the problem im getting, is that i get an mysql error saying, name is not on group by, well if i add name on group by it wont groupby content id and it will show repeat values...this is what i have:
DB::table('mytable')
->addselect(DB::Raw('sum(items) as items'))
->addselect(DB::Raw('name as name'))
->addselect(DB::Raw('id as id'))
->groupBy('id')
->get();
I need to display the name and items with sum, grouped by id.
Doing example above im getting mysql error asking to add name on groupby...witch gives me repeats values.