A free open source IT asset/license management system
Use snake case for naming paths
sniped6ca8468e352
diff --git a/app/Http/Requests/ImageUploadRequest.php b/app/Http/Requests/ImageUploadRequest.phpindex abb0cee5f7..52d61d5bd3 100644--- a/app/Http/Requests/ImageUploadRequest.php+++ b/app/Http/Requests/ImageUploadRequest.php@@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Storage;use Intervention\Image\Exception\NotReadableException;use Illuminate\Support\Facades\Log;use Illuminate\Support\Facades\Validator;+use Illuminate\Support\Str;class ImageUploadRequest extends Request{@@ -70,11 +71,12 @@ class ImageUploadRequest extends Requestpublic function handleImages($item, $w = 600, $form_fieldname = 'image', $path = null, $db_fieldname = 'image'){- $type = strtolower(class_basename(get_class($item)));+ $type = Str::snake(class_basename(get_class($item)));if (is_null($path)) {- $path = str_plural($type);+ \Log::debug('path is null');+ $path = Str::of(str_plural($type))->snake();if ($type == 'assetmodel') {$path = 'models';@@ -85,6 +87,11 @@ class ImageUploadRequest extends Request}}++ if (!Storage::exists($path)) {+ Storage::makeDirectory($path);+ }+if ($this->offsetGet($form_fieldname) instanceof UploadedFile) {$image = $this->offsetGet($form_fieldname);} elseif ($this->hasFile($form_fieldname)) {@@ -96,7 +103,7 @@ class ImageUploadRequest extends Requestif (!config('app.lock_passwords')) {$ext = $image->guessExtension();- $file_name = $type.'-'.$form_fieldname.'-'.$item->id.'-'.str_random(10).'.'.$ext;+ $file_name = $type.'-'.$form_fieldname.($item->id ?? '-'.$item->id).'-'.str_random(10).'.'.$ext;if (($image->getMimeType() == 'image/vnd.microsoft.icon') || ($image->getMimeType() == 'image/x-icon') || ($image->getMimeType() == 'image/avif') || ($image->getMimeType() == 'image/webp')) {// If the file is an icon, webp or avif, we need to just move it since gd doesn't support resizing