What goes in the yellow fields? The names of those who attended or a count of how many attended?
And I would suggest learning sql, instead of turning off strict mode :)
Oh and as you arent using eloquent at all, your relationships arent used either
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, this is my first post here, please accept my greetings. My query is that, I have two tables.
// SchoolClass.php
public function attendances()
{
return $this->hasMany('App\Attendance');
}
// Attendance.php
public function schoolClass()
{
return $this->belongsTo('App\SchoolClass');
}
I want to achieve something like in this screenshot- Imgur
I tried something like this, and many other ways but none is working.
$data = DB::table('attendances')
->join('school_classes', 'school_classes.id', '=', 'attendances.school_class_id')
->select('attendances.*','school_classes.class_grade')
->groupBy('school_classes.class_grade')
->get();
Try this instead
$data = DB::table('attendances')
->join('school_classes', 'school_classes.id', '=', 'attendances.school_class_id')
->select(DB::raw('count(attendances.present) as attendance_count, school_classes.class_grade, attendances.date'))
->groupBy('school_classes.class_grade', 'attendances.date')
->get();
Please or to participate in this conversation.