<?php namespace App\Models; use Illuminate\Database\Eloquent\Model; class Scholarship extends Model { protected $table = 'scholarships'; protected $primaryKey = 'scholarship_id'; public $incrementing = false; protected $keyType = 'string'; public $timestamps = false; protected $guarded = []; public function checklists() { return $this->hasMany(GuidanceChecklist::class, 'scholarship_id', 'scholarship_id'); } public function applications() { return $this->hasMany(StudentApplication::class, 'scholarship_id', 'scholarship_id'); } public static function calculateEligibility( Scholarship $scholarship, float $studentCgpa, ?string $studentField ): float { // Step 1: Calculate CGPA Score (70%) if ($scholarship->min_cgpa <= 0) { $cgpaScore = 70; } else { $cgpaScore = min( $studentCgpa / $scholarship->min_cgpa, 1 ) * 70; } // Step 2: Calculate Field of Study Score (30%) $scholarshipField = trim( (string) $scholarship->field_of_study ); $studentField = trim((string) $studentField); if ( $scholarshipField === '' || strtolower($scholarshipField) === 'open' || ( $studentField !== '' && strcasecmp($scholarshipField, $studentField) === 0 ) ) { $fieldScore = 30; } else { $fieldScore = 0; } // Step 3: Calculate Final Score $totalScore = $cgpaScore + $fieldScore; // Step 4: Return score between 0 and 100 return round( max(0, min($totalScore, 100)), 2 ); } }
You have javascript disabled. You will not be able to edit any code.