Files
alrahma_sunday_school_api/app/Models/FinalScore.php
T
2026-04-23 00:04:35 -04:00

67 lines
1.6 KiB
PHP

<?php
namespace App\Models;
use App\Models\BaseModel;
class FinalScore extends BaseModel
{
protected $table = 'final_score';
// CI 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 CI 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;
}
}