From f49e25ea1f8072042cc026b0cb7279d40a8f6a6e Mon Sep 17 00:00:00 2001 From: rahul shukla Date: Mon, 9 Sep 2019 18:34:02 +0530 Subject: [PATCH] Issue #1259 --- .../Product/src/Http/Requests/ProductForm.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/Webkul/Product/src/Http/Requests/ProductForm.php b/packages/Webkul/Product/src/Http/Requests/ProductForm.php index c813b406c..c7912f721 100755 --- a/packages/Webkul/Product/src/Http/Requests/ProductForm.php +++ b/packages/Webkul/Product/src/Http/Requests/ProductForm.php @@ -79,6 +79,12 @@ class ProductForm extends FormRequest $inputs = $this->all(); + if (isset($inputs['variants'])) { + foreach ($inputs['variants'] as $key => $variant) { + $this->rules['variants'.'.'.$key.'.'.'sku'] = ['unique:products,sku,' . $key, new \Webkul\Core\Contracts\Validations\Slug]; + } + } + $product = $this->product->find($this->id); $attributes = $product->attribute_family->custom_attributes; @@ -131,4 +137,16 @@ class ProductForm extends FormRequest return $this->rules; } + + /** + * Custom message for validation + * + * @return array + */ + public function messages() + { + return [ + 'variants.*.sku.unique' => 'The sku has already been taken.', + ]; + } }