belongsTo(Department::class); } public function faculty() { return $this->department->faculty(); } public function semesters() { return $this->belongsToMany(Semester::class, 'sections'); } public function sections() { return $this->hasMany(Section::class); } /** * Return count of sections in a given semester. * * @param string $sem_code * @return int */ public function getSemesterSectionCount($sem_code) { return $this->sections->where('semester_code', '=', $sem_code)->count(); } }