62 lines
1.3 KiB
PHP
62 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
|
|
class SchoolClass extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $table = 'classes';
|
|
|
|
protected $fillable = [
|
|
'academic_year_id',
|
|
'department_id',
|
|
'name',
|
|
'level',
|
|
'homeroom_teacher',
|
|
'capacity',
|
|
'is_active',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'capacity' => 'integer',
|
|
'is_active' => 'boolean',
|
|
];
|
|
}
|
|
|
|
public function academicYear(): BelongsTo
|
|
{
|
|
return $this->belongsTo(AcademicYear::class);
|
|
}
|
|
|
|
/**
|
|
* Scope: hanya kelas pada tahun ajaran yang sedang aktif.
|
|
*/
|
|
public function scopeForActiveAcademicYear($query)
|
|
{
|
|
return $query->whereHas('academicYear', fn ($q) => $q->where('is_active', true));
|
|
}
|
|
|
|
public function department(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Department::class);
|
|
}
|
|
|
|
public function students(): HasMany
|
|
{
|
|
return $this->hasMany(Student::class, 'class_id');
|
|
}
|
|
|
|
public function academicHistories(): HasMany
|
|
{
|
|
return $this->hasMany(StudentAcademicHistory::class, 'class_id');
|
|
}
|
|
}
|