Files
portal-api/app/Mail/Admin/TicketAdminNotification.php
T
2026-09-09 16:56:22 +07:00

51 lines
1.6 KiB
PHP

<?php
namespace App\Mail\Admin;
use App\Mail\Concerns\RequiresDbTemplate;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Queue\SerializesModels;
class TicketAdminNotification extends Mailable implements ShouldQueue
{
use Queueable, SerializesModels, RequiresDbTemplate;
public function __construct(
public readonly mixed $ticket,
public readonly mixed $customer,
) {}
public function envelope(): Envelope
{
return new Envelope(
subject: $this->renderFromTemplate('admin_ticket_notification', $this->vars())['subject'],
);
}
public function content(): Content
{
return new Content(
htmlString: $this->renderFromTemplate('admin_ticket_notification', $this->vars())['html'],
);
}
private function vars(): array
{
$description = strip_tags($this->ticket->description ?? '');
return [
'ticket_num' => $this->ticket->ticket_num,
'subject_text' => $this->ticket->subject,
'room' => $this->ticket->room ?? 'N/A',
'customer_name' => trim($this->customer->firstname . ' ' . $this->customer->lastname) ?: 'N/A',
'customer_email'=> $this->customer->email,
'description' => mb_substr($description, 0, 500) . (mb_strlen($description) > 500 ? '…' : ''),
'ticket_url' => config('app.frontend_url') . '/tickets/' . $this->ticket->ticket_num,
];
}
}