You can try this in your controller-
$attendedStudents = Attendance::where('present', 1)->get();
$nonattendedStudents = Attendance::where('present', 0)->get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello all,
I could really use some help with the following:
I am building a class schedule with students that attend and dont attend class on a given day.
My database table has 4 columns:
class_id(foreign key) student_id(foreign key)
present(boolean 0/1)
date.
Writing sql at phpmyadmin I have achieved this:
SELECT student_id ,class_id
FROM attendance
WHERE present = 1(present) .
However, I don't know how to apply this using blade and eloquent,query builder to get to:
Class 1: student_id = 1 (present) student_id = 1 (present)
Class 2: student_id = 1 (present) student_id = 1 (present)
Please or to participate in this conversation.