Feb 8, 2021
0
Level 6
updating the multiple image gets deleted non-updated image
i am doing ecommerce project ,for the product i have setup 4 images per products but while updating the product image it gets updated but non updated imge gets deleted my model is
public function delete_images(){
Storage::delete($this->product_image_1);
Storage::delete($this->product_image_2);
Storage::delete($this->product_image_3);
Storage::delete($this->product_image_4);
}
controller is
public function update(editProductRequest $request, Products $product)
{
$data=$request->only([
'category_id',
'subcategory_id',
'brand_id',
'product_name',
'product_code',
'product_quantity',
'product_detail',
'product_color',
'product_size',
'selling_price',
'discount_price',
'video_link',
'main_slider',
'hot_deal',
'best_rated',
'mid_slider',
'hot_new',
'trend',
'status']);
if($request->hasFile('product_image_1')){
$product_image_1=$request->product_image_1->store('products','public');
$product->delete_images();
$data['product_image_1']=$product_image_1;
}
if($request->hasFile('product_image_2')){
$product_image_2=$request->product_image_2->store('products','public');
$product->delete_images();
$data['product_image_2']=$product_image_2;
}
if($request->hasFile('product_image_3')){
$product_image_3=$request->product_image_3->store('products','public');
$product->delete_images();
$data['product_image_3']=$product_image_3;
}
if($request->hasFile('product_image_4')){
$product_image_4=$request->product_image_4->store('products','public');
$product->delete_images();
$data['product_image_4']=$product_image_4;
}
$product->update($data);
toastr()->success('Product updated successfully');
return redirect(route('products.index'));
}
how can i correct it
Please or to participate in this conversation.