У меня следующий MySql запрос:
SELECT DISTINCT students.fname, students.lname, students.year_level
FROM (students, teachers)
JOIN teacher_subjects ON teachers.teacherID = teacher_subjects.teacherID
JOIN subjects ON teacher_subjects.subjectID = subjects.subjectID
JOIN teacher_sections ON teachers.teacherID = teacher_sections.teacherID
JOIN student_subjects ON students.studentID = student_subjects.subjectID
JOIN sections ON students.sectionID = sections.sectionID
WHERE teacher_sections.sectionID = students.sectionID
AND student_subjects.subjectID = teacher_subjects.subjectID
У кого-нибудь есть идеи, как преобразовать это в построитель запросов Laravel? Спасибо.
Я пробовал это, но это не работает
$student = DB::table('students', 'teachers')
->join('teacher_subjects','teachers.teacherID', '=', 'teacher_subjects.teacherID')
->join('subjects','teacher_subjects.subjectID', '=', 'subjects.subjectID')
->join('teacher_sections','teachers.teacherID', '=', 'teacher_sections.teacherID')
->join('student_subjects','students.studentID', '=', 'student_subjects.subjectID')
->join('sections','students.sectionID','=','sections.sectionID')
->select('students.fname', 'students.lname', 'students.year_level')
->where([
['teacher_sections.sectionID', '=', 'student.sectionID'],
['student_subjects.subjectID', '=', 'teacher_subjects.subjectID']
])
->distinct()
->get();
return view('teacher_class', compact('student'));