From 8b05909b748964de923da948546e2d26b4b52024 Mon Sep 17 00:00:00 2001 From: yogesh_gohil Date: Wed, 20 Nov 2019 17:46:45 +0530 Subject: [PATCH] fix customer email validation --- app/Http/Controllers/CustomersController.php | 1 + app/Http/Requests/CustomerRequest.php | 1 - resources/assets/js/views/customers/Create.vue | 7 ++++++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/CustomersController.php b/app/Http/Controllers/CustomersController.php index 6d2e4bac..79fc1d57 100644 --- a/app/Http/Controllers/CustomersController.php +++ b/app/Http/Controllers/CustomersController.php @@ -160,6 +160,7 @@ class CustomersController extends Controller if ($verifyEmail) { if ($verifyEmail->id !== $customer->id) { return response()->json([ + 'success' => false, 'error' => 'Email already in use' ]); } diff --git a/app/Http/Requests/CustomerRequest.php b/app/Http/Requests/CustomerRequest.php index be8e5c96..d93e5de1 100644 --- a/app/Http/Requests/CustomerRequest.php +++ b/app/Http/Requests/CustomerRequest.php @@ -36,7 +36,6 @@ class CustomerRequest extends FormRequest 'name' => 'required', 'addresses.*.address_street_1' => 'max:255', 'addresses.*.address_street_2' => 'max:255', - 'email' => 'email|nullable|unique:users,email,'.$this->id ]; break; default: diff --git a/resources/assets/js/views/customers/Create.vue b/resources/assets/js/views/customers/Create.vue index 27125885..2973ad4d 100644 --- a/resources/assets/js/views/customers/Create.vue +++ b/resources/assets/js/views/customers/Create.vue @@ -586,11 +586,16 @@ export default { this.isLoading = true try { let response = await this.updateCustomer(this.formData) - if (response.data) { + if (response.data.success) { window.toastr['success'](this.$t('customers.updated_message')) this.$router.push('/admin/customers') this.isLoading = false return true + } else { + this.isLoading = false + if (response.data.error) { + window.toastr['error'](this.$t('validation.email_already_taken')) + } } } catch (err) { if (err.response.data.errors.email) {