isValid()) { continue; } $disk = (string) config('helpdesk.disk', 'public'); $originalName = $file->getClientOriginalName(); $mimeType = $file->getClientMimeType(); $size = (int) ($file->getSize() ?: 0); $path = $file->store('tickets/'.$ticket->id, $disk); if ($size === 0 && $path !== false) { $size = (int) Storage::disk($disk)->size($path); } Attachment::query()->create([ 'ticket_id' => $ticket->id, 'comment_id' => $comment?->id, 'user_id' => $userId, 'disk' => $disk, 'path' => $path, 'original_name' => $originalName, 'mime_type' => $mimeType, 'size' => $size, ]); } } /** * Delete a stored attachment and its backing file. */ public function delete(Attachment $attachment): void { Storage::disk($attachment->disk)->delete($attachment->path); $attachment->delete(); } }