sohail49
1 month ago

check for duplicate when updating database

Posted 1 month ago by sohail49

hey guys I create a product table but I am updating the product and enter a new name then it works but when I enter the name that is in the database Its throws an error so far everything works

but lets I want to update the price and image not the name and when I click on an update I still throw an error instead I should be updated

here is the code

	 $duplicate = Product::where('name', $request->name)->first();
                if ($request->name == $duplicate->name) {
                    exit;
                }else{
		run the code ...
	}

I know my code I wrong but does anyone know how to do this

Please sign in or create an account to participate in this conversation.