belongsTo(Department::class); } public function faculty() { return $this->department->faculty(); } public function sections() { return $this->belongsToMany(Section::class)->withPivot('percent', 'schedule', 'eval'); } public function semesters() { return $this->belongsToMany(Semester::class)->withPivot('admin_load', 'investigative_load', 'other'); } public function getFullNameAttribute() { return "{$this->first_name} {$this->last_name}"; } // public function getSectionLoad(Section $section) { // return ($section->pivot->percent ?? 1.0) * (($section->credits ?? 0.0) + calcExtraCredits($section->credits, $section->student_count)); // } public function getAcademicLoad(Semester $semester) { $prof_sections = $this->sections->where('semester_code', '=', $semester->code); return $prof_sections->reduce(function ($carry, $section) { return $carry + (($section->pivot->percent ?? 100.0) / 100.0) * (($section->credits ?? 0.0) + $section->extra_credits); }, 0); } }