*/ public function via(object $notifiable): array { $preferences = $notifiable->notification_preferences ?? []; $channels = $preferences['broken_links'] ?? ['mail']; return $channels; } /** * Get the mail representation of the notification. */ public function toMail(object $notifiable): MailMessage { $brokenLinkCount = count($this->brokenLinks); $message = (new MailMessage) ->warning() ->subject("⚠️ Broken Links Detected: {$this->site->name}") ->line("We detected **{$brokenLinkCount}** broken link(s) on **{$this->site->name}**.") ->line("Site URL: {$this->site->url}") ->line('') ->line('**Broken Links:**'); // Add up to 10 broken links to the email $displayLimit = min(10, $brokenLinkCount); foreach (array_slice($this->brokenLinks, 0, $displayLimit) as $link) { $message->line("• {$link['url']} (HTTP {$link['status_code']})"); } if ($brokenLinkCount > $displayLimit) { $remaining = $brokenLinkCount - $displayLimit; $message->line("... and {$remaining} more"); } $message->line('') ->action('View All Broken Links', url("/sites/{$this->site->id}/broken-links")) ->line('Please fix these broken links to improve user experience and SEO.'); return $message; } /** * Get the array representation of the notification. * * @return array */ public function toArray(object $notifiable): array { return [ 'site_id' => $this->site->id, 'site_name' => $this->site->name, 'site_url' => $this->site->url, 'broken_link_count' => count($this->brokenLinks), 'broken_links' => $this->brokenLinks, ]; } }