From ad85f8be2fa5e4661f5f419760cd6d76606a7774 Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 20 Jul 2024 05:55:12 +0100 Subject: [PATCH] Cleaned up Signed-off-by: snipe --- app/Http/Requests/ImageUploadRequest.php | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/app/Http/Requests/ImageUploadRequest.php b/app/Http/Requests/ImageUploadRequest.php index 9dd89a8af6..abb0cee5f7 100644 --- a/app/Http/Requests/ImageUploadRequest.php +++ b/app/Http/Requests/ImageUploadRequest.php @@ -136,29 +136,28 @@ class ImageUploadRequest extends Request } // Remove Current image if exists - $item = $this->deleteExistingImage($item, $form_fieldname, $path, $db_fieldname); + $item = $this->deleteExistingImage($item, $path, $db_fieldname); $item->{$db_fieldname} = $file_name; } // If the user isn't uploading anything new but wants to delete their old image, do so } elseif ($this->input('image_delete') == '1') { - $item = $this->deleteExistingImage($item, $form_fieldname, $path, $db_fieldname); + $item = $this->deleteExistingImage($item, $path, $db_fieldname); } return $item; } - public function deleteExistingImage($item, $form_fieldname = 'image', $path = null, $db_fieldname = 'image') { + public function deleteExistingImage($item, $path = null, $db_fieldname = 'image') { - \Log::error('DELETING '.$form_fieldname); - - try { - Storage::disk('public')->delete($path.'/'.$item->{$db_fieldname}); - $item->{$db_fieldname} = null; - \Log::error('deleted successfully'); - } catch (\Exception $e) { - Log::debug($e); + if ($item->{$db_fieldname}!='') { + try { + Storage::disk('public')->delete($path.'/'.$item->{$db_fieldname}); + $item->{$db_fieldname} = null; + } catch (\Exception $e) { + Log::debug($e); + } } return $item;