Ignore unique validation while update data - development

Ignore unique validation while update data

In my products table product_name is unique so while updating the data if i don’t update the product name it can’t let me update my product information and showing

product name has already been taken

My question is how to ignore unique name while while updating same product. Here is the code i have used for updating.

public function update(Request $request, $id)
  {
     $product = Product::find($id);     
     $this->validate($request, [ 
         'product_name'=> 'unique:products,product_name,'.$product->id ,          
     ]);  
     $product->product_name = Input::get('product_name'); 
     $product->product_unit_price = Input::get('product_unit_price');
     $product->save();         
     return Redirect::to('products');
  }



from Laravel Questions and Answers https://laravelquestions.com/php/ignore-unique-validation-while-update-data/
via Lzo Media

Comments

Popular posts from this blog

ng-show doesn’t work correct with value boolean

Using PHP and MySQL data to generate PDF letters like in MS Word mailmerge functionality - development

ng-include of inline SVG does not display gradient except in Chrome