diff --git a/src/App/Http/Controllers/SelectionValueController.php b/src/App/Http/Controllers/SelectionValueController.php index 7a5c7b7..d15d5ef 100644 --- a/src/App/Http/Controllers/SelectionValueController.php +++ b/src/App/Http/Controllers/SelectionValueController.php @@ -47,12 +47,16 @@ 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());