Updated the helpdesk module

This commit is contained in:
Mark Gregory
2026-06-14 15:48:28 +01:00
parent ac19c8ef37
commit 91b600a4fe
+13 -10
View File
@@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Modules\Helpdesk\Services; namespace Modules\Helpdesk\Services;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Modules\Helpdesk\Models\Attachment; use Modules\Helpdesk\Models\Attachment;
use Modules\Helpdesk\Models\Comment; use Modules\Helpdesk\Models\Comment;
@@ -12,26 +11,30 @@ use Modules\Helpdesk\Models\Ticket;
final class AttachmentService final class AttachmentService
{ {
/**
* Store uploaded files against a ticket and optional comment.
*
* @param array<int, UploadedFile> $files
*/
public function storeMany(Ticket $ticket, array $files, int $userId, ?Comment $comment = null): void public function storeMany(Ticket $ticket, array $files, int $userId, ?Comment $comment = null): void
{ {
foreach ($files as $file) { foreach ($files as $file) {
$disk = (string) config('helpdesk.disk'); $disk = (string) config('helpdesk.disk', 'public');
$originalName = $file->getClientOriginalName();
$mimeType = $file->getClientMimeType();
$size = (int) ($file->getSize() ?: 0);
$path = $file->store('tickets/'.$ticket->id, $disk); $path = $file->store('tickets/'.$ticket->id, $disk);
if ($size === 0 && $path !== false) {
$size = (int) Storage::disk($disk)->size($path);
}
Attachment::query()->create([ Attachment::query()->create([
'ticket_id' => $ticket->id, 'ticket_id' => $ticket->id,
'comment_id' => $comment?->id, 'comment_id' => $comment?->id,
'user_id' => $userId, 'user_id' => $userId,
'disk' => $disk, 'disk' => $disk,
'path' => $path, 'path' => $path,
'original_name' => $file->getClientOriginalName(), 'original_name' => $originalName,
'mime_type' => $file->getClientMimeType(), 'mime_type' => $mimeType,
'size' => $file->getSize() ?: 0, 'size' => $size,
]); ]);
} }
} }