'integer', 'school_id' => 'integer', 'class_section_id' => 'integer', 'updated_by' => 'integer', // score can be decimal; change to 'integer' if it's whole number 'score' => 'decimal:2', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /* Optional relationships */ public function student() { return $this->belongsTo(Student::class, 'student_id'); } public function classSection() { return $this->belongsTo(ClassSection::class, 'class_section_id'); } /** * Equivalent of CI getMidtermExamScore() */ public static function getMidtermExamScore( int $studentId, ?string $semester, string $schoolYear, ?int $classSectionId = null ) { $q = static::query() ->select('score') ->where('student_id', $studentId) ->where('school_year', $schoolYear); if ($semester !== null && $semester !== '') { $q->where('semester', $semester); } if ($classSectionId !== null) { $q->where('class_section_id', $classSectionId); } $row = $q->first(); return $row?->score; } }