message = $this->generateMessage(); } /** * Get the notification's delivery channels. * * @return array */ public function via(object $notifiable): array { return ['mail', 'database']; } /** * Get the mail representation of the notification. */ public function toMail(object $notifiable): MailMessage { return (new MailMessage) ->view('emails.undertime', [ 'headerImageUrl' => asset('images/AUTOHUB25_BANNER.png'), // URL of the image 'msg' => $this->message, 'notifiable' => $notifiable, ]) ->subject('Undertime Notification'); } /** * Get the array representation of the notification. * * @return array */ public function toArray(object $notifiable): array { return [ 'undertime_id' => $this->undertime->id, 'status' => $this->undertime->status, 'approved_at' => $this->undertime->approved_at, 'message' => $this->message, 'title' => ($this->undertime->status == 2) ? "Your undertime application has been approved" : (($this->undertime->status == 99) ? "Your undertime application has been denied" : $this->undertime->employee->firstname . ' ' . $this->undertime->employee->lastname." Submitted Undertime Application" ), 'url' => 'attendance/undertime', 'created_by' => $this->undertime->employee_id ]; } private function generateMessage(): string { $fullname = $this->undertime->employee->firstname.' '.$this->undertime->employee->lastname; $date = $this->undertime->date; $from_time = $this->undertime->from_time; $to_time = $this->undertime->to_time; switch ($this->undertime->status) { case 1: case 0: return $fullname.' filed undertime application dated "'.$date. '" time from "'.$from_time.'" to "'.$to_time.'" for your validation.'; case 2: return 'Your undertime application dated "'.$date. '" time from "'.$from_time.'" to "'.$to_time.'" has been approved.'; case 99: return 'Your undertime application dated "'.$date. '" time from "'.$from_time.'" to "'.$to_time.'" has been denied.'; default: return 'Unknown status.'; } } }