Files
alrahma_sunday_school_api/app/Models/ParentNotification.php
T
2026-06-08 23:30:22 -04:00

62 lines
1.4 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',
];
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');
}
}