From c6694de2fa9285b15f7b43caf729fc9516edff27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nikola=20Ga=C5=A1pari=C4=87?= Date: Mon, 21 Oct 2024 16:28:33 +0200 Subject: [PATCH 1/2] hf fix new --- .../Http/Controllers/SelectionValueController.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/App/Http/Controllers/SelectionValueController.php b/src/App/Http/Controllers/SelectionValueController.php index 7a5c7b7..a2db484 100644 --- a/src/App/Http/Controllers/SelectionValueController.php +++ b/src/App/Http/Controllers/SelectionValueController.php @@ -47,12 +47,17 @@ public function store(SelectionValueRequest $request): JsonResponse ->where('value', $request->get('value')) ->first(); - if ($selectionValue->trashed()) { - // restore - $selectionValue->restoreQuietly(); - $selectionValue->update($request->validated()); + if ($selectionValue) { + if ($selectionValue->trashed()) { + // restore + $selectionValue->restoreQuietly(); + $selectionValue->update($request->validated()); + } + else { + throw new Exception('Selection value already exists.', 400); + } } else { - throw new Exception('Selection value already exists.', 400); + $selectionValue = $this->selectionValue::query()->create($request->validated()); } } else { $selectionValue = $this->selectionValue::query()->create($request->validated()); From adebffaeac12d426de3faaebaf6332cc67981537 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Mon, 21 Oct 2024 14:28:44 +0000 Subject: [PATCH 2/2] Apply fixes from StyleCI --- src/App/Http/Controllers/SelectionValueController.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/App/Http/Controllers/SelectionValueController.php b/src/App/Http/Controllers/SelectionValueController.php index a2db484..d15d5ef 100644 --- a/src/App/Http/Controllers/SelectionValueController.php +++ b/src/App/Http/Controllers/SelectionValueController.php @@ -52,8 +52,7 @@ public function store(SelectionValueRequest $request): JsonResponse // restore $selectionValue->restoreQuietly(); $selectionValue->update($request->validated()); - } - else { + } else { throw new Exception('Selection value already exists.', 400); } } else {