<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Semester extends Model
{
    public $primaryKey = 'code';
    public $incrementing = false;
    public $timestamps = false;

    protected $keyType = 'string';


    public function courses() {
        return $this->belongsToMany(Course::class, 'sections');
    }

    public function sections() {
        return $this->hasMany(Section::class);
    }

    public function professors() {
        return $this->belongsToMany(Professor::class)->withPivot('admin_load', 'investigative_load');
    }

    public function getIsFutureAttribute() {
        return Semester::orderBy('code', 'desc')->take(6)->get()->contains('code', $this->code);
    }


}