Attendize/app/Notifications/TicketReceived.php

93 lines
2.4 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)
{
2020-05-06 17:19:57 +00:00
try{
Log::info('Mail Notification: ',$notifiable);
2020-05-06 17:19:57 +00:00
if($notifiable instanceof HelpTicket){
return (new MailMessage)
->line('The introduction to the notification.')
2020-05-06 17:28:28 +00:00
->line($this->ticket->text)
->line($this->ticket->created_at)
2020-05-06 17:19:57 +00:00
->action('Notification Action', route('help.show',['code' => $this->ticket->code]))
->line('Thank you for using our application!');
}
else
return (new MailMessage)
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-06 17:19:57 +00:00
->action('Notification Action', 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();
2020-05-06 16:08:44 +00:00
Log::info('Database Notification: ',$notifiable);
2020-05-06 14:28:06 +00:00
}
}