Files
alrahma_sunday_school_api/app/Models/FinalScore.php
T
2026-06-08 23:30:22 -04:00

66 lines
1.6 KiB
PHP

<?php
namespace App\Models;
class FinalScore extends BaseModel
{
protected $table = 'final_score';
// legacy model didn't specify timestamps behavior; table includes created_at/updated_at.
// If you want Laravel to auto-manage them, keep true (recommended).
public $timestamps = true;
protected $fillable = [
'student_id',
'school_id',
'class_section_id',
'teacher_id',
'score',
'score_letter',
'comment',
'semester',
'school_year',
'created_at',
'updated_at',
];
protected $casts = [
'student_id' => 'integer',
'school_id' => 'integer',
'class_section_id' => 'integer',
'teacher_id' => 'integer',
'score' => 'decimal:2', // change to 'integer' if score is whole number
];
/* Optional relationships */
public function student()
{
return $this->belongsTo(Student::class, 'student_id');
}
public function teacher()
{
return $this->belongsTo(User::class, 'teacher_id');
}
public function classSection()
{
return $this->belongsTo(ClassSection::class, 'class_section_id');
}
/**
* Equivalent of legacy getFinalExamScore()
*/
public static function getFinalExamScore(int $studentId, string $semester, string $schoolYear)
{
$row = static::query()
->select('score')
->where('student_id', $studentId)
->where('semester', $semester)
->where('school_year', $schoolYear)
->first();
return $row?->score;
}
}