Files
alrahma_sunday_school_api/app/Models/FamilyStudent.php
T
root e13df69885
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 4m53s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 59s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
fix unittests issues
2026-07-07 20:56:32 -04:00

51 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Support\Facades\DB;
class FamilyStudent extends BaseModel
{
protected $table = 'family_students';
// legacy model didn't specify timestamps
public $timestamps = true;
protected $fillable = ['family_id', 'student_id', 'is_primary_home', 'notes', 'created_at', 'updated_at'];
protected $casts = [
'family_id' => 'integer',
'student_id' => 'integer',
'is_primary_home' => 'boolean',
];
/* Optional relationships */
public function family()
{
return $this->belongsTo(Family::class, 'family_id');
}
public function student()
{
return $this->belongsTo(Student::class, 'student_id');
}
/**
* Laravel equivalent of legacy getFamiliesForStudent().
* Returns array rows: families.* + is_primary_home
*/
public static function getFamiliesForStudent(int $studentId): array
{
return DB::table('family_students as fs')
->join('families as f', 'f.id', '=', 'fs.family_id')
->where('fs.student_id', $studentId)
->where('f.is_active', 1)
->orderByDesc('fs.is_primary_home')
->orderBy('f.household_name')
->select('f.*', 'fs.is_primary_home')
->get()
->map(fn ($r) => (array) $r)
->all();
}
}