certificate = $certificate; $this->daysRemaining = $daysRemaining; } /** * Get the notification's delivery channels. * * @return array */ public function via($notifiable) { $channels = ['database']; if ($this->daysRemaining < 7) { $channels[] = 'mail'; } return $channels; } /** * Get the mail representation of the notification. */ public function toMail($notifiable) { return (new \App\Mail\CertificateExpiringMail($this->certificate, $this->daysRemaining)) ->to($notifiable->email); } /** * Get the array representation of the notification. * * @return array */ public function toDatabase($notifiable) { return [ 'type' => 'certificate_expiring', 'certificate_id' => $this->certificate->id, 'common_name' => $this->certificate->common_name, 'days_remaining' => $this->daysRemaining, 'valid_to' => $this->certificate->valid_to, 'message' => "Certificate '{$this->certificate->common_name}' expires in {$this->daysRemaining} days.", ]; } }