subjects; } public function getAllSubjects(): Collection { return Subject::all(); } public function create(array $data, ?Model $model = null): Grade { $model->subjects()->syncWithoutDetaching($data['subject_id']); return $model; } public function update(Model $model, array $data, ?Model $subject = null): Grade { $model->subjects()->detach($subject->id); $model->subjects()->attach($data['subject_id']); return $model; } public function delete(Model $model, ?Model $subject = null): Grade { $model->subjects()->detach($subject); return $model; } }