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.leave', [ 'headerImageUrl' => asset('images/AUTOHUB25_BANNER.png'), // URL of the image 'msg' => $this->message, 'notifiable' => $notifiable, ]) ->subject('Leave Notification'); } /** * Get the array representation of the notification. * * @return array */ public function toArray(object $notifiable): array { $title = null; $isApprover = false; if($this->leave->validated == 1){ $title = "Your leave application has been received and validated by HR"; }else if($this->leave->validated == 99){ $title = "Your leave application has been denied by HR"; }else if($this->leave->status == 2){ $title = "Your leave application has been approved"; }else if($this->leave->status == 99){ $title = "Your leave application has been denied"; }else{ $title = $this->leave->employee->firstname . ' ' . $this->leave->employee->lastname." Submitted Leave Application"; $isApprover = true; } return [ 'leave_id' => $this->leave->id, 'status' => $this->leave->status, 'approved_at' => $this->leave->approved_at, 'message' => $this->message, 'title' => $title, 'url' => $isApprover ? 'attendance/leave-approval' : 'attendance/leave', 'created_by' => $this->leave->employee_id ]; } /** * Generate the message based on leave status. */ private function generateMessage(): string { $fullname = $this->leave->employee->firstname . ' ' . $this->leave->employee->lastname; $date_from = $this->leave->date_from; $date_to = $this->leave->date_to; $leave_type = $this->leave->leave_type->name; $created_at = Carbon::parse($this->leave->created_at)->setTimezone('Asia/Shanghai'); switch ($this->leave->status) { case 1: case 0: return "$fullname filed a $leave_type application dated \"$date_from\" to \"$date_to\" for your validation."; case 2: if($this->leave->validated == 1){ return "Your application for $leave_type dated \"$date_from\" to \"$date_to\" has been received and alidated by HR."; }else if($this->leave->validated == 99){ return "Your application for $leave_type dated \"$date_from\" to \"$date_to\" has been denied by HR."; }else{ return "Your application for $leave_type dated \"$date_from\" to \"$date_to\" has been approved."; } case 99: return "Your application for $leave_type dated \"$date_from\" to \"$date_to\" has been denied."; default: return 'Unknown status.'; } } }