JSTR
JSTR

Reputation: 151

Laravel Eloquent Array foreach

Hey guys Im new to laravel. I have this table

enter image description here

How will i able to fetch count of 'is_correct' column for each subject?

Thanks guys!

Upvotes: 0

Views: 52

Answers (1)

Kenath
Kenath

Reputation: 630

Try this, replace the Model with your eloquent model name

Model::select(
'subject_id',
 Illuminate\Support\Facades\DB::raw("COUNT(is_correct) as count")
)
->groupBy('subject_id')
->get();

Upvotes: 1

Related Questions