belongsTo(Lesson::class)->select(['id', 'name', 'lesson_hour', 'credit']); } public function teacher() { // return $this->belongsTo(Teacher::class)->select(['id', 'name', 'account']); return $this->belongsTo(Admin::class, 'teacher_admin_id')->select(['id', 'name', 'username']); } public function getProgressAttribute() { $id = $this->attributes['id']; $total = LessonSchedule::query()->where('lesson_teacher_id', $id)->where('status', ModelStatusEnum::OK)->count(); $current = LessonSchedule::query()->where('lesson_teacher_id', $id)->where('day', '<', date('Y-m-d'))->where('status', ModelStatusEnum::OK)->count(); if (!$total) return 0; return round($current / $total * 100); } public function grade() { return $this->belongsTo(Grade::class)->select(['id', 'name']); } }