singleloginsystem/app/Notifications/TicketCommentedNotification.php
= 67002d6979 Feat: add ticket assignment, comments, and notifications
- Added migration for ticket assignment and comments (`assigned_user_id` and `ticket_replies` table).
- Implemented `TicketAssignedNotification` and `TicketCommentedNotification`.
- Created `ReplyData`, `TicketListData`, and `PostReplyRequest` data classes.
- Introduced `ResolveNotificationRouteController` for modular notification redirection.
- Updated UI to support assigning users and posting comments on tickets.
- User is navigated to comments page when clicked on the ticket, upon navigation ticket details modal is opened.
- Extended tests to cover assignments, comments, status transitions, and notifications.
2026-05-26 07:01:18 +00:00

70 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Notifications;
use App\Models\{Ticket, TicketReply};
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Str;
class TicketCommentedNotification extends Notification implements ShouldQueue
{
use Queueable;
public function __construct(
public readonly Ticket $ticket,
public readonly TicketReply $comment
) {}
/**
* 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
{
$commenterName = $this->comment->user->name;
return (new MailMessage())
->subject("New Comment on Ticket: {$this->ticket->ticket_id}")
->greeting('Hello,')
->line("{$commenterName} left a new comment on ticket {$this->ticket->ticket_id} regarding {$this->ticket->issue_category}.")
->line('Comment: "'.Str::limit($this->comment->message, 300).'"')
->action('View Discussion', 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
{
$commenterName = $this->comment->user->name;
$appName = $this->ticket->connectedApp->name ?? 'General Inquiry';
return [
'ticket_id' => $this->ticket->id,
'ticket_code' => $this->ticket->ticket_id,
'user_name' => $commenterName,
'issue_category' => $this->ticket->issue_category,
'app_name' => $appName,
'description' => Str::limit($this->ticket->description ?? '', 100),
'message' => "{$commenterName} commented on ticket {$this->ticket->ticket_id}.",
];
}
}