Attendize/app/Notifications/TicketCommented.php

80 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2020-05-06 15:53:50 +00:00
<?php
namespace App\Notifications;
2020-06-02 08:13:35 +00:00
use App\Models\BackpackUser;
2020-05-06 15:53:50 +00:00
use App\Models\HelpTicketComment;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
2020-06-02 08:13:35 +00:00
use Illuminate\Support\Facades\Log;
2020-05-06 15:53:50 +00:00
2020-05-06 16:01:08 +00:00
class TicketCommented extends Notification implements ShouldQueue
2020-05-06 15:53:50 +00:00
{
use Queueable;
/**
* Create a new notification instance.
*
* @return void
*/
protected $comment;
2020-05-15 07:22:05 +00:00
public $tries = 2;
2020-05-06 15:53:50 +00:00
public function __construct(HelpTicketComment $comment)
{
$this->comment = $comment;
//
}
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @return array
*/
public function via($notifiable)
{
2020-05-08 10:54:00 +00:00
return ['mail','database'];
2020-05-06 15:53:50 +00:00
}
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
2020-06-02 08:13:35 +00:00
try{
if($notifiable instanceof BackpackUser){
return (new MailMessage)
->line('New comment on ticket №'.$this->comment->ticket->code)
->line($this->comment->text)
->line($this->comment->created_at)
->action('Reply here', route('ticket.replay',['id'=>$this->comment->help_ticket_id]));
}
else
return (new MailMessage)
->view('Emails.Help.CommentNotification',['comment' => $this->comment]);
}
catch (\Exception $ex){
Log::error($ex);
}
2020-05-06 15:53:50 +00:00
}
/**
* Get the array representation of the notification.
*
* @param mixed $notifiable
* @return array
*/
2020-05-08 10:54:00 +00:00
public function toDatabase($notifiable)
2020-05-06 15:53:50 +00:00
{
2020-05-08 10:54:00 +00:00
return $this->comment->toArray();
2020-05-06 15:53:50 +00:00
}
}