I would have the same approach.
To select the count from something grouped, you can use a Raw exression. The group by clause is simple.
$ethnicityAndCountArray = Employee::select(DB::Raw('Ethnicity, COUNT(*) as count'))
->groupBy('Ethnicity');
The result will be an array with objects containing Ethnicity and count each.
$total = 0;
foreach($ethnicityAndCountArray as $ethnicity)
$total += $ethnicity->count;
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community