<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Exam extends Model
{
  use HasFactory;

  protected $table = 'exams';

  protected $fillable = ['date', 'subject_id', 'title', 'remarks'];

  public function teachers()
  {
    return $this->belongsToMany(
      'App\Models\Teacher',
      'exam_teacher_rel',
      'exam_id',
      'teacher_id'
    );
  }

  public function students()
  {
    return $this->belongsToMany(
      'App\Models\Student',
      'exam_student_rel',
      'exam_id',
      'student_id'
    );
  }

  public function exam_results()
  {
    return $this->belongsToMany(
      'App\Models\ExamResult',
      'exam_exam_result_rel',
      'exam_id',
      'exam_result_id'
    );
  }

  public function subject()
  {
    return $this->belongsTo('App\Models\Subject');
  }
}
