I am looking for a sql request which will provide this kind of result.
id | family result :
1 A [A => 2, B => 1, C => 1]
2 A
3 B
4 C
Preferably using eloquent.
Current solution :
materials()->select('family', DB::raw('count(*) as total'))
->groupBy('family')
->pluck('total', 'family');