Attendize/app/Notifications/TicketReceived.php

89 lines
2.2 KiB
PHP
Raw Normal View History

2020-05-06 14:28:06 +00:00
<?php
namespace App\Notifications;
use App\Models\HelpTicket;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
2020-05-06 16:08:44 +00:00
use Illuminate\Support\Facades\Log;
2020-05-06 14:28:06 +00:00
class TicketReceived extends Notification implements ShouldQueue
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
2020-05-06 16:56:39 +00:00
/**
* The maximum number of exceptions to allow before failing.
*
* @var int
*/
public $maxExceptions = 3;
2020-05-06 14:28:06 +00:00
protected $ticket;
public function __construct(HelpTicket $ticket)
{
$this->ticket = $ticket;
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
return $notifiable instanceof HelpTicket ? ['mail'] : ['mail','database'];
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
Log::info($notifiable);
2020-05-06 17:19:57 +00:00
try{
if($notifiable instanceof HelpTicket){
2020-05-11 09:41:53 +00:00
return (new MailMessage)->from(config('mail.from_help.address'),config('mail.from.name'))
->view('Emails.Help.CustomerNotification',['ticket' => $this->ticket]);
2020-05-06 17:19:57 +00:00
}
else
return (new MailMessage)
2020-05-11 09:41:53 +00:00
->from(config('mail.from_help.address'),config('mail.from.name'))
2020-05-06 14:28:06 +00:00
->line('You have new ticket')
2020-05-06 17:28:28 +00:00
->line($this->ticket->text)
->line($this->ticket->created_at)
2020-05-11 09:41:53 +00:00
->action('Reply here', route('ticket.replay',['id'=>$this->ticket->id]))
2020-05-06 14:28:06 +00:00
->line('Thank you for using our application!');
2020-05-06 16:08:44 +00:00
2020-05-06 17:19:57 +00:00
}
catch (\Exception $ex){
Log::error($ex);
}
2020-05-06 14:28:06 +00:00
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase($notifiable)
{
return $this->ticket->toArray();
}
}