説明なし

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 department() {
  17. return $this->belongsTo(Department::class);
  18. }
  19. public function faculty() {
  20. return $this->department->faculty();
  21. }
  22. public function semesters() {
  23. return $this->belongsToMany(Semester::class, 'sections');
  24. }
  25. public function sections() {
  26. return $this->hasMany(Section::class);
  27. }
  28. /**
  29. * Return count of sections in a given semester.
  30. *
  31. * @param string $sem_code
  32. * @return int
  33. */
  34. public function getSemesterSectionCount($sem_code) {
  35. return $this->sections->where('semester_code', '=', $sem_code)->count();
  36. }
  37. }