12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
-
- namespace App;
-
- use Illuminate\Database\Eloquent\Model;
-
- class Course extends Model
- {
- protected $guarded = [
- 'id'
- ];
-
- protected $fillable = [
- 'code',
- 'title',
- 'syllabus',
- 'dept_id',
- ];
-
- public $timestamps = false;
-
- public function dept() {
- return $this->belongsTo(Dept::class);
- }
-
- 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();
- }
- }
|