Нет описания

Course.php 1021B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. // dd($this->hasManyThrough(Semester::class, Section::class, 'course_id', 'code'));
  21. // dd($this->hasManyThrough(Semester::class, Section::class, 'course_id', 'code')->get());
  22. return $this->belongsToMany(Semester::class, 'sections');
  23. }
  24. public function sections() {
  25. return $this->hasMany(Section::class);
  26. }
  27. /**
  28. * Return count of sections in a given semester.
  29. *
  30. * @param string $sem_code
  31. * @return int
  32. */
  33. public function getSemesterSectionCount($sem_code) {
  34. return $this->sections->where('semester_code', '=', $sem_code)->count();
  35. }
  36. }