In my controller i was trying to update my product, product name here is unique and here i wanted to update only price. so name will be as it but as i defined name as a unique field though i haven't changed the name it throws me unique name validation error as this name already exist. How do i ignore that validation request when i don't update the unique value?
public function update(Request $request, $id)
{
$this->validate($request, [
'name'=> 'required|unique:products,'.$id,
]);
$product= Product::find($id);
$product->name = Input::get('name');
$product->price = Input::get('price');
$product->save();
}
Change it to:
'name'=> 'required|unique:products,name' . $id,
Add unique column name
to validation rule:
'name'=> 'required|unique:products,name,'.$id,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With