v1.0.0
This commit is contained in:
50
src/app/Notifications/TicketNotification.php
Normal file
50
src/app/Notifications/TicketNotification.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\EmailTemplate;
|
||||
use App\Models\Ticket;
|
||||
use App\Support\Settings;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class TicketNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(protected Ticket $ticket, protected int $emailTemplateId) {}
|
||||
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$template = EmailTemplate::query()->find($this->emailTemplateId);
|
||||
|
||||
$firstName = trim(explode(' ', $this->ticket->name)[0] ?? $this->ticket->name);
|
||||
|
||||
$rendered = $template?->render([
|
||||
'numer' => $this->ticket->number,
|
||||
'imie' => $firstName,
|
||||
'temat' => $this->ticket->subject,
|
||||
'status' => $this->ticket->statusLabel(),
|
||||
'kategoria' => $this->ticket->categoryLabel(),
|
||||
'priorytet' => $this->ticket->priorityLabel(),
|
||||
'zespol' => $this->ticket->team?->name ?? 'Brak',
|
||||
'operator' => $this->ticket->assignee?->name ?? 'Nieprzypisane',
|
||||
'link' => route('client.ticket', $this->ticket),
|
||||
]) ?? [
|
||||
'subject' => 'Zgłoszenie #'.$this->ticket->number,
|
||||
'body' => $this->ticket->subject,
|
||||
];
|
||||
|
||||
return (new MailMessage)
|
||||
->subject($rendered['subject'])
|
||||
->view('emails.ticket-notification', [
|
||||
'html' => Settings::renderEmailLayout($rendered['body']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user