add projet

This commit is contained in:
root
2026-03-05 12:29:37 -05:00
parent 8d1eef8ba8
commit 23b7db1107
9109 changed files with 1106501 additions and 73 deletions
+62
View File
@@ -0,0 +1,62 @@
<?php
namespace App\Models;
use App\Models\BaseModel;
class StudentAllergy extends BaseModel
{
protected $table = 'student_allergies';
protected $primaryKey = 'id';
protected $fillable = [
'student_id',
'allergy',
];
public $timestamps = false;
protected $validationRules = [
'student_id' => 'required|is_natural_no_zero',
'allergy' => 'required|string|max_length[100]',
];
protected $validationMessages = [
'student_id' => [
'required' => 'Student ID is required.',
'is_natural_no_zero' => 'Invalid Student ID.',
],
'allergy' => [
'required' => 'Allergy is required.',
'max_length' => 'Allergy must be 100 characters or fewer.',
],
];
/**
* Get all allergies for a given student.
*
* @param int $studentId
* @return array
*/
public function getAllergiesByStudentId(int $studentId): array
{
return $this->where('student_id', $studentId)
->findAll();
}
/**
* Get allergies for multiple students.
*
* @param array $studentIds
* @return array grouped by student_id
*/
public function getAllergiesByStudentIds(array $studentIds): array
{
$rows = $this->whereIn('student_id', $studentIds)->findAll();
$grouped = [];
foreach ($rows as $row) {
$grouped[$row['student_id']][] = $row;
}
return $grouped;
}
}