'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'); } }