$teacher, 'subject' => $subject, 'grades' => $subject->grades, ]); } public function store(GradeTeacherPostRequest $request, Teacher $teacher, Subject $subject): RedirectResponse { $teacher->grades()->syncWithoutDetaching($request->grade_id); return redirect()->route('teachers.subjects.show', [ $teacher, $subject, ]); } public function edit(Teacher $teacher, Subject $subject, Grade $grade): View { return view('grade-teacher.edit', [ 'teacher' => $teacher, 'subject' => $subject, 'updateGrade' => $grade, 'grades' => $subject->grades, ]); } public function update(GradeTeacherPostRequest $request, Teacher $teacher, Subject $subject, Grade $grade): RedirectResponse { $teacher->grades()->detach($grade); $teacher->grades()->attach($request->grade_id); return redirect()->route('teachers.subjects.show', [ $teacher, $subject, ]); } public function destroy(Teacher $teacher, Subject $subject, Grade $grade): RedirectResponse { $teacher->grades()->detach($grade); return redirect()->route('teachers.subjects.show', [ $teacher, $subject, ]); } }