$data['email'], 'password' => $data['password'], ]); $student = Student::create([ 'name' => $data['name'], 'last_name' => $data['last_name'], 'middle_name' => $data['middle_name'], 'birthday' => $data['birthday'], 'grade_id' => $data['grade_id'], ]); $student->user()->save($user); $student ->lessons() ->syncWithPivotValues($student->grade->lessons->pluck('id')->all(), ['score' => ScoreEnum::WithoutScore]); return $student; } public function update(Student $student, array $data): Student { $student->user()->update([ 'email' => $data['email'], 'password' => $data['password'], ]); $student->update([ 'name' => $data['name'], 'last_name' => $data['last_name'], 'middle_name' => $data['middle_name'], 'birthday' => $data['birthday'], 'grade_id' => $data['grade_id'], ]); return $student; } public function delete($model): void { $model->user()->delete(); $model->delete(); } }