= 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

112 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\{Model, SoftDeletes};
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Relations\{BelongsTo, BelongsToMany, HasMany};
use Illuminate\Support\Str;
#[Fillable([
'ticket_id',
'user_id',
'connected_app_id',
'issue_category',
'description',
'status_id',
'assigned_user_id',
])]
class Ticket extends Model
{
use SoftDeletes;
protected static function booted(): void
{
static::creating(function (Ticket $ticket): void {
if (empty($ticket->ticket_id)) {
do {
$ticketId = 'TKT-'.mb_strtoupper(Str::random(8));
} while (static::query()->where('ticket_id', $ticketId)->exists());
$ticket->ticket_id = $ticketId;
}
});
}
/**
* @return BelongsTo<User, $this>
*/
public function user(): BelongsTo
{
return $this->belongsTo(User::class, 'user_id');
}
/**
* @return BelongsTo<ConnectedApp, $this>
*/
public function connectedApp(): BelongsTo
{
return $this->belongsTo(ConnectedApp::class, 'connected_app_id');
}
/**
* @return BelongsTo<TicketStatus, $this>
*/
public function status(): BelongsTo
{
return $this->belongsTo(TicketStatus::class, 'status_id');
}
/**
* @return BelongsTo<User, $this>
*/
public function assignedUser(): BelongsTo
{
return $this->belongsTo(User::class, 'assigned_user_id');
}
/**
* @return BelongsToMany<Role, $this>
*/
public function notifiedRoles(): BelongsToMany
{
return $this->belongsToMany(
Role::class,
'ticket_notified_roles',
'ticket_id',
'role_id'
);
}
/**
* @return BelongsToMany<User, $this>
*/
public function notifiedUsers(): BelongsToMany
{
return $this->belongsToMany(
User::class,
'ticket_notified_users',
'ticket_id',
'user_id'
);
}
/**
* @return HasMany<TicketAttachment, $this>
*/
public function attachments(): HasMany
{
return $this->hasMany(TicketAttachment::class, 'ticket_id');
}
/**
* @return HasMany<TicketReply, $this>
*/
public function replies(): HasMany
{
return $this->hasMany(TicketReply::class, 'ticket_id');
}
}