$files * @param int $userId * @param Comment|null $comment * @return void */ public function storeMany(Ticket $ticket, array $files, int $userId, ?Comment $comment = null): void { foreach ($files as $file) { $disk = (string) config('helpdesk.disk'); $path = $file->store('tickets/' . $ticket->id, $disk); Attachment::query()->create([ 'ticket_id' => $ticket->id, 'comment_id' => $comment?->id, 'user_id' => $userId, 'disk' => $disk, 'path' => $path, 'original_name' => $file->getClientOriginalName(), 'mime_type' => $file->getClientMimeType(), 'size' => $file->getSize() ?: 0, ]); } } /** * Delete a stored attachment and its backing file. * * @param Attachment $attachment * @return void */ public function delete(Attachment $attachment): void { Storage::disk($attachment->disk)->delete($attachment->path); $attachment->delete(); } }