Untitled
/****************/ Add a field In products Table /****************/ image_reviews /****************/ ProductController in store() method /****************/ if($request->image_reviews){ if ($request->hasFile('image_reviews')) { $image = $request->file('image_reviews'); foreach ($image as $files) { $file_name = rand() . "." . $files->getClientOriginalExtension(); $destinationPath = 'backend/img/products/'.$file_name; Image::make($files)->resize(600, 600)->save($destinationPath); $data[] = $file_name; } } $product->image_reviews=json_encode($data); } /****************/ ProductController in update() method /****************/ if($request->image_reviews){ if(!is_null($product->image_reviews)){ foreach (json_decode($product->image_reviews) as $area) { if (File::exists('backend/img/products/' . $area)) { File::delete('backend/img/products/' . $area); } } } if ($request->hasFile('image_reviews')) { $image = $request->file('image_reviews'); foreach ($image as $files) { $file_name = rand() . "." . $files->getClientOriginalExtension(); $destinationPath = 'backend/img/products/'.$file_name; Image::make($files)->resize(800, 800)->save($destinationPath); $data[] = $file_name; } } $product->image_reviews=json_encode($data); } /********/ backend.product.create /*********/ <div class="mt-3 row"> <label class="col-sm-3 form-control-label">Reviews Image (400*400)</label> <div class="col-sm-9 mg-t-10 mg-sm-t-0"> <input type="file" name="image_reviews[]" multiple class="form-control-file"> </div> </div> /********/ backend.product.edit /*********/ <div class="mt-3 row"> <label class="col-sm-3 form-control-label">Reviews Image</label> <div class="col-sm-9 mg-t-10 mg-sm-t-0"> @if($product->image_reviews) @foreach (json_decode($product->image_reviews) as $area) <img src="{{ asset('backend/img/products/'.$area) }}" width="50"> @endforeach @endif <input type="file" name="image_reviews[]" multiple class="form-control-file"> </div> </div> /********/ frontend.pages.landing2 /*********/ <tr> <td> <div class="product-image" > @if(!is_null($landing->product->gallery_images)) @foreach (json_decode($landing->product->gallery_images) as $area) <img width="40px" height="40px" src="{{ asset('backend/img/products/'.$area) }}" alt="image"> @endforeach @endif </div> </td> </tr>
Leave a Comment