Files
alrahma_sunday_school_api/app/Models/ParentNotification.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;
class ParentNotification extends BaseModel
{
protected $table = 'parent_notifications';
// ✅ legacy: useTimestamps = true (created_at/updated_at)
public $timestamps = true;
protected $fillable = ['student_id', 'code', 'incident_date', 'channel', 'to_address', 'subject', 'status', 'response', 'semester', 'school_year', 'created_at', 'updated_at'];
protected $casts = [
'student_id' => 'integer',
// incident_date is stored as Y-m-d in legacy usage
'incident_date' => 'date',
];
/* Optional relationships */
public function student()
{
return $this->belongsTo(Student::class, 'student_id');
}
/**
* Equivalent of legacy hasSent()
*/
public static function hasSent(
int $studentId,
string $code,
string $incidentYmd,
string $channel = 'email',
?string $to = null
): bool {
$q = static::query()
->where('student_id', $studentId)
->where('code', $code)
->whereDate('incident_date', $incidentYmd)
->where('channel', $channel);
if (! empty($to)) {
$q->where('to_address', $to);
}
$row = $q->orderByDesc('id')->first();
return $row && (($row->status ?? '') === 'sent');
}
}