subjects; } public function getAllSubjects(): Collection { return Subject::all(); } public function getGrades(Teacher $teacher, Subject $subject): Collection { return $teacher ->grades() ->join('grade_subject', 'grades.id', '=', 'grade_subject.grade_id') ->where('subject_id', $subject->id)->get(); } public function create(array $data, ?Model $model = null): Teacher { $model->subjects()->syncWithoutDetaching($data['subject_id']); return $model; } public function update(Model $model, array $data, ?Model $subject = null): Teacher { $model->subjects()->detach($subject->id); $model->subjects()->attach($data['subject_id']); return $model; } public function delete(Model $model, ?Model $subject = null): Teacher { $model->subjects()->detach($subject); return $model; } }