select('claim_dump_date') ->where('client_policy_id', $policyId) ->where('is_active', 1) ->where('claim_dump_date IS NOT NULL', null, false) ->where("TRIM(claim_dump_date) != ''", null, false) ->orderBy('claim_dump_date', 'DESC') ->orderBy('id', 'DESC') ->first(); $raw = trim((string) ($row['claim_dump_date'] ?? '')); if ($raw === '') { return null; } $ts = strtotime($raw); return $ts === false ? null : $ts; } /** * Latest claim_dump_date for a policy, formatted. * Returns null when no dump file has a claim_dump_date. */ public function getGeneratedAtForPolicy(int $policyId, string $format = 'd-m-Y'): ?string { $ts = $this->getLatestClaimDumpTimestamp($policyId); if ($ts === null) { return null; } return date($format, $ts); } }