I'm new to Laravel. All I'm trying to do is as follow:
I have some fields in my form like TITLE, DESCRIPTION.
TITLE field is unique in database.
This is what I've done to update my values.
$product = Product::find($id);
$product->title = $request->title;
$product->description = $request->description;
$product->save();
But this will give error (that value already exists) as my TITLE field is unique.
All I want to is update my TITLE only if the TITLE value is changed otherwise update the same value but update other fields. Thanks
Something like this?
$product = Product::find($id);
if ($product->title == $request->title) {
$product->description = $request->description;
} else {
$product->title = $request->title;
}
$product->save();
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