morphTo(); } /** * Decide whether the public link backed by this row still works. * * A link dies with its document: once the referenced record is gone the * link is treated as expired rather than as an error. Otherwise expiry is * opt-in per company — with `automatically_expire_public_links` switched on, * the link lasts `link_expiry_days` days from the moment this row was * written, compared at whole-day granularity. */ public function isExpired(): bool { $document = $this->mailable; if (! $document) { return true; } $lifespanInDays = (int) CompanySetting::getSetting('link_expiry_days', $document->company_id); $expiryEnabled = CompanySetting::getSetting('automatically_expire_public_links', $document->company_id); $lastValidDay = $this->created_at->addDays($lifespanInDays); return $expiryEnabled == 'YES' && Carbon::now()->format('Y-m-d') > $lastValidDay->format('Y-m-d'); } }