You can use distinct or groupBy('students.id')
https://laravel.com/docs/8.x/queries#specifying-a-select-clause
But for groupBy('students.id') you will have a problem about strict mode.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
$this->studentsTeacher = DB::table('students')
->join('attendances', 'students.id', '=', 'attendances.student_id')
->where('attendances.teacher_id', $this->teacherId)
->select('students.*')
->get();
I made the error of connecting the student to the teacher through this attendance db, I am now at a problem where I want to just call a list of students for a teacher, but of course, if there are many attendances then the student will get called again, resulting in multiple students being shown on the classroom roster table.
Now, I am not sure how to go about, is there a little work around with the DB query, or should I write another DB which will just have teacherid, studentid, or just add a teacher id on the student table. I am not sure, which would you say be the best work for solution.
You can use distinct or groupBy('students.id')
https://laravel.com/docs/8.x/queries#specifying-a-select-clause
But for groupBy('students.id') you will have a problem about strict mode.
Please or to participate in this conversation.