57 lines
1.2 KiB
PHP
57 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
|
|
class TeacherSubject extends Model
|
|
{
|
|
protected $fillable = ['teacher_id', 'subject_id', 'class_id', 'academic_year'];
|
|
|
|
/**
|
|
* Get the teacher associated with this assignment
|
|
*/
|
|
public function teacher(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class, 'teacher_id');
|
|
}
|
|
|
|
/**
|
|
* Get the subject associated with this assignment
|
|
*/
|
|
public function subject(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Subject::class, 'subject_id');
|
|
}
|
|
|
|
/**
|
|
* Get the class associated with this assignment
|
|
*/
|
|
public function class(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ClassRoom::class, 'class_id');
|
|
}
|
|
|
|
/**
|
|
* Scope for current academic year
|
|
*/
|
|
public function scopeCurrentYear($query)
|
|
{
|
|
return $query->where('academic_year', now()->format('Y'));
|
|
}
|
|
|
|
/**
|
|
* Scope for specific academic year
|
|
*/
|
|
public function scopeForYear($query, $year)
|
|
{
|
|
return $query->where('academic_year', $year);
|
|
}
|
|
|
|
public function attendances()
|
|
{
|
|
return $this->hasMany(Attendances::class);
|
|
}
|
|
}
|