= cac5f4905b WIP: implement ticketing system with support for notifications and attachments
- Added database migrations for tickets, statuses, roles, users, and related associations.
- Introduced models and enums for ticket status, permissions, and notifications.
- Implemented `TicketService` for ticket management and notification handling.
- Created Livewire form and UI for raising tickets with file attachments and routing options.
- Added tests covering ticket creation, validation, notifications, and file uploads.
2026-05-25 13:04:43 +00:00

96 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\{Model, SoftDeletes};
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',
])]
class Ticket extends Model
{
use HasFactory, 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 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');
}
}