diff --git a/app/Http/Controllers/ContactsController.php b/app/Http/Controllers/ContactsController.php index 7224354d..68f06e0f 100644 --- a/app/Http/Controllers/ContactsController.php +++ b/app/Http/Controllers/ContactsController.php @@ -178,9 +178,17 @@ public function addColumn() 'type' => ['required', 'in:string,number,date'], ]); - Auth::user()->account->contactCustomColumns()->create($column); + if (Auth::user()->account->contactCustomColumns()->where('name', $column['name'])->exists()) { + return Redirect::back()->with('error', 'Column already exists.'); + } else { - return Redirect::back()->with('success', 'Column added.'); + Auth::user()->account->contactCustomColumns()->create($column); + + //send status 200 code + return response()->json([], 200); + + return Redirect::back()->with('success', 'Column added.')->json([], 200); + } } public function updateCustomColumns(Contact $contact): RedirectResponse diff --git a/resources/js/Pages/Contacts/Index.vue b/resources/js/Pages/Contacts/Index.vue index cbb2ba59..e1d1af76 100644 --- a/resources/js/Pages/Contacts/Index.vue +++ b/resources/js/Pages/Contacts/Index.vue @@ -28,7 +28,7 @@