I'm developing an application, where I'm creating dynamic input. Validation is working properly except one use case.
Validation rule is here:
return [ '*.id' => 'nullable|numeric', '*.name' => 'required|min:3|regex:/^[a-zA-Z0-9\s]+$/|unique:products,name,*.id,id,category_id,'.$this->route('id'), '*.quantity_available' => 'nullable|numeric|min:0', '*.quantity_sold' => 'nullable|numeric|min:0', '*.price'=> 'required|numeric|min:10', '*.sale_price' => 'required|numeric|min:10', ];
Please have a look over the following sent data:
{id: 5, category_id: 3, name: "Test 1", description: null, quantity_available: null, quantity_sold: null, price:40, sale_price:35}, {id: 6, category_id: 3, name: "Test 2", description: null, quantity_available: null, quantity_sold: null,price:40, sale_price:35}, {id: "", name: "Test 3", quantity_available: "", quantity_sold: "", price: 40, sale_price: 35}
Query: I want the product name to be unique as per the category_id and if a input has id present, then that product id would be ignored while product name unique validation.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire