$teacher, 'subjects' => Subject::all(), ]); } public function store(SubjectTeacherPostRequest $request, Teacher $teacher): RedirectResponse { $teacher->subjects()->syncWithoutDetaching($request->subject_id); return redirect()->route('teachers.show', $teacher); } public function show(Teacher $teacher, Subject $subject): View { return view('subject-teacher.show', [ 'teacher' => $teacher, 'subject' => $subject, 'grades' => $teacher ->grades() ->join('grade_subject', 'grades.id', '=', 'grade_subject.grade_id') ->where('subject_id', $subject->id)->get(), ]); } public function edit(Teacher $teacher, Subject $subject): View { return view('subject-teacher.edit', [ 'teacher' => $teacher, 'updateSubject' => $subject, 'subjects' => Subject::all(), ]); } public function update(SubjectTeacherPostRequest $request, Teacher $teacher, Subject $subject): RedirectResponse { $teacher->subjects()->detach($subject); $teacher->subjects()->attach($request->subject_id); return redirect()->route('teachers.show', $teacher); } public function destroy(Teacher $teacher, Subject $subject): RedirectResponse { $teacher->subjects()->detach($subject); return redirect()->route('teachers.show', $teacher); } }