public static function boot() { parent::boot(); ExamMember::deleting(function ($exam_member) { $exam_member->answers()->delete(); }); }
public function deleteMember($user = null) { if ($user) { $this->setUser($user); } ExamMember::where('user_id', $this->user->id)->whereHas('exam', function ($query) { $query->where('course_id', $this->model->id); })->delete(); QuizMember::where('user_id', $this->user->id)->whereHas('quiz', function ($quiz) { $quiz->whereHas('chapter', function ($chapter) { $chapter->where('course_id', $this->model->id); }); })->delete(); $this->model->members()->detach($user); return $this; }