Skip to content

Commit fc21dba

Browse files
ngaspariStyleCIBot
andauthored
fix custom field selection values add new (#95)
* hf fix new * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <[email protected]>
1 parent 00c6451 commit fc21dba

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/App/Http/Controllers/SelectionValueController.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ public function store(SelectionValueRequest $request): JsonResponse
4747
->where('value', $request->get('value'))
4848
->first();
4949

50-
if ($selectionValue->trashed()) {
51-
// restore
52-
$selectionValue->restoreQuietly();
53-
$selectionValue->update($request->validated());
50+
if ($selectionValue) {
51+
if ($selectionValue->trashed()) {
52+
// restore
53+
$selectionValue->restoreQuietly();
54+
$selectionValue->update($request->validated());
55+
} else {
56+
throw new Exception('Selection value already exists.', 400);
57+
}
5458
} else {
55-
throw new Exception('Selection value already exists.', 400);
59+
$selectionValue = $this->selectionValue::query()->create($request->validated());
5660
}
5761
} else {
5862
$selectionValue = $this->selectionValue::query()->create($request->validated());

0 commit comments

Comments
 (0)