Aucune description

Course.php 830B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App;
  3. use Illuminate\Database\Eloquent\Model;
  4. class Course extends Model
  5. {
  6. protected $guarded = [
  7. 'id'
  8. ];
  9. protected $fillable = [
  10. 'code',
  11. 'title',
  12. 'syllabus',
  13. 'dept_id',
  14. ];
  15. public $timestamps = false;
  16. public function dept() {
  17. return $this->belongsTo(Dept::class);
  18. }
  19. public function semesters() {
  20. return $this->belongsToMany(Semester::class, 'sections');
  21. }
  22. public function sections() {
  23. return $this->hasMany(Section::class);
  24. }
  25. /**
  26. * Return count of sections in a given semester.
  27. *
  28. * @param string $sem_code
  29. * @return int
  30. */
  31. public function getSemesterSectionCount($sem_code) {
  32. return $this->sections->where('semester_code', '=', $sem_code)->count();
  33. }
  34. }