HardDrive's avatar

Laravel Eloquent groupBy() and get count of each group

if I have a table containing a job and a job can have a status of one of three values. What is the Laravel/Eloquent way of getting a count of each status?

I can do with separate count queries but not sure how to group-by and count with Eloquent.

0 likes
2 replies
staudenmeir's avatar
Level 24
Job::select('status', DB::raw('count(*) count'))->groupBy('status')->get();
1 like

Please or to participate in this conversation.