$grade, 'subjects' => Subject::all(), ]); } public function store(GradeSubjectPostRequest $request, Grade $grade): RedirectResponse { $grade->subjects()->syncWithoutDetaching($request->subject_id); return redirect()->route('grades.show', $grade); } public function edit(Grade $grade, Subject $subject): View { return view('grade-subject.edit', [ 'grade' => $grade, 'updateSubject' => $subject, 'subjects' => Subject::all(), ]); } public function update(GradeSubjectPostRequest $request, Grade $grade, Subject $subject): RedirectResponse { $grade->subjects()->detach($subject); $grade->subjects()->attach($request->subject_id); return redirect()->route('grades.show', $grade); } public function destroy(Grade $grade, Subject $subject): RedirectResponse { $grade->subjects()->detach($subject); return redirect()->route('grades.show', $grade); } }