singleloginsystem/app/Notifications/TicketStatusChangedNotification.php
= 8a41ae6ac1 Feat: assigned user status change, search, pagination and notification
- Added activity logs for ticket status changes, comments, and ticket views.
- Implemented `TicketStatusChangedNotification` to notify users of status updates.
- Enhanced ticket list filtering with pagination, search, and status filters.
- Updated UI to better handle ticket assignments, status updates, and comment notifications.
- Extended tests for activity logs, unauthorized actions, status change notifications, and filtering functionalities.
2026-05-28 13:22:36 +00:00

70 lines
2.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Notifications;
use App\Enums\TicketStatusEnum;
use App\Models\Ticket;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;
class TicketStatusChangedNotification extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
public readonly Ticket $ticket
) {}
/**
* Get the notification's delivery channels.
*
* @return array<int, string>
*/
public function via(object $notifiable): array
{
return ['database', 'mail'];
}
/**
* Get the mail representation of the notification.
*/
public function toMail(object $notifiable): MailMessage
{
$statusLabel = TicketStatusEnum::tryFrom($this->ticket->status->name)?->label() ?? ucfirst($this->ticket->status->name);
return (new MailMessage())
->subject("SSO Support Ticket Status Changed: {$this->ticket->ticket_id}")
->greeting('Hello,')
->line("The status of your support ticket {$this->ticket->ticket_id} regarding {$this->ticket->issue_category} has been updated.")
->line("New Status: {$statusLabel}")
->action('View Ticket Details', route('tickets.index'))
->line('Thank you for using our application!');
}
/**
* Get the array representation of the notification.
*
* @return array<string, mixed>
*/
public function toArray(object $notifiable): array
{
$appName = $this->ticket->connectedApp->name ?? 'General Inquiry';
$statusLabel = TicketStatusEnum::tryFrom($this->ticket->status->name)?->label() ?? ucfirst($this->ticket->status->name);
return [
'ticket_id' => $this->ticket->id,
'ticket_code' => $this->ticket->ticket_id,
'user_name' => $this->ticket->user->name,
'issue_category' => $this->ticket->issue_category,
'app_name' => $appName,
'description' => Str::limit($this->ticket->description ?? '', 100),
'message' => "The status of your support ticket {$this->ticket->ticket_id} has been changed to {$statusLabel}.",
];
}
}