singleloginsystem/app/Services/TicketAttachmentService.php
= 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

41 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Services;
use App\Models\TicketAttachment;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\DB;
use InvalidArgumentException;
final class TicketAttachmentService
{
/**
* Store a ticket attachment and create the database record.
*
* @throws InvalidArgumentException
*/
public function store(int $ticketId, UploadedFile $file): TicketAttachment
{
if ($ticketId <= 0) {
throw new InvalidArgumentException('Invalid ticket ID');
}
return DB::transaction(function () use ($ticketId, $file): TicketAttachment {
$path = $file->store('tickets/attachments', 'public');
/** @var TicketAttachment $attachment */
$attachment = TicketAttachment::query()->create([
'ticket_id' => $ticketId,
'file_path' => $path,
'file_name' => $file->getClientOriginalName(),
'file_size' => $file->getSize(),
'mime_type' => $file->getMimeType() ?? 'application/octet-stream',
]);
return $attachment;
});
}
}