ShamiCanCode's avatar

E commerce

I gave an option to update the product but when the user clicks on the update button All the information of the product e.g product name, product price but the product images are not in input type file value. what should I do If the user wants to update only the name of the product. He has to upload that images again. Any Solution the images files are already in upload images section

0 likes
2 replies
viorel's avatar

HI @shamicancode,

The easiest way to solve is to add to the methid used for saving the data a check to see if a image is present. If it's not present skip this field on update.


public function update(Product $product, Request $request) {

   $product->name = $request->name;
   // other fileds and check for image
   if ($request->has('image')) {
        $product->image = $request->image;
   }
   $product->save();
    // do other things here
}

What I showed above is one way. You can tweak it as necessary.

Please or to participate in this conversation.