Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Notifications;
- use App\Ticket;
- use App\User;
- use Illuminate\Bus\Queueable;
- use Illuminate\Notifications\Notification;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Notifications\Messages\MailMessage;
- use Illuminate\Support\Facades\Storage;
- class ReviewRequestSubmittedNotification extends Notification implements ShouldQueue
- {
- use Queueable;
- public $ticket;
- /**
- * Create a new notification instance.
- *
- * @return void
- */
- public function __construct(Ticket $ticket)
- {
- $this->ticket = $ticket;
- }
- /**
- * Get the notification's delivery channels.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function via($notifiable)
- {
- return ['mail', 'database'];
- }
- /**
- * Get the mail representation of the notification.
- *
- * @param mixed $notifiable
- * @return \Illuminate\Notifications\Messages\MailMessage
- */
- public function toMail($notifiable)
- {
- $mail = (new MailMessage)->subject('Review Request ' . $this->ticket->ticket_number)
- ->markdown('mails.' . substr($this->ticket->ticketable_type . '.review-request', 4), [
- 'ticket' => $this->ticket
- ]);
- if ($this->ticket->ticketable->attachments) {
- foreach ($this->ticket->ticketable->attachments as $attachment) {
- $encryptedContent = Storage::get($attachment->path);
- $decryptedContent = decrypt($encryptedContent);
- $mail->attachData($decryptedContent, $attachment->filename);
- }
- }
- // cc to HoD PIC
- $hodPic = User::find($this->ticket->department->head_of_department_id);
- if ($hodPic) {
- $mail->cc($hodPic);
- }
- // cc to HoD Requester
- $hodRequester = User::find($this->ticket->requesterDepartment->head_of_department_id);
- if ($hodRequester) {
- $mail->cc($hodRequester);
- }
- return $mail;
- }
- /**
- * Get the array representation of the notification.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function toArray($notifiable)
- {
- return [
- 'message' => 'User ' . $this->ticket->requester->name . ' need your assistant to review something. Please click to review.',
- 'url' => $this->ticket->url,
- 'path' => $this->ticket->path
- ];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement