JOHNMAC's avatar

image is not showing in index page from admin panel

hi m trying to show products from admin panel to index page, when i add product(its image and its details) then this is showing in admin view products but only details are showing in index.blade.php, or image is not showing:

  @foreach($productsALL as $product)
  <img src="{{ asset('images/backend_images/products/small/'.$product->image) }}" 
  alt="IMG-PRODUCT">
  @endforeach

here is code of upload image:

  if($request->hasFile('image')){
            $image_tmp = Input::file('image');
            if ($image_tmp->isValid()) {
                // Upload Images after Resize
                $extension = $image_tmp->getClientOriginalExtension();
                $fileName = rand(111,99999).'.'.$extension;
                $large_image_path = 'images/backend_images/product/large'.'/'.$fileName;
                $medium_image_path = 'images/backend_images/product/medium'.'/'.$fileName;  
                $small_image_path = 'images/backend_images/product/small'.'/'.$fileName;  

                Image::make($image_tmp)->save($large_image_path);
                Image::make($image_tmp)->resize(600, 600)->save($medium_image_path);
                Image::make($image_tmp)->resize(300, 300)->save($small_image_path);

                $product->image = $fileName; 

            }
        }

any seggestion to resolve this issue

0 likes
8 replies
Nakov's avatar

I believe that the problem is because of missing / at the beginning of the URL, so I assume that your images folder is within the public directory, then just changing it with this:

  <img src="{{ asset('/images/backend_images/products/small/'.$product->image) }}" 

will do the work. Because when you are on the index page, it uses the correct path, but when you are on different page, for example yourdomain.com/products it will try to find the image in products/images ... instead of just yourdomain.com/images. Hope this helps.

Nakov's avatar

@AAAA1111 - Can you please check in your browser, inspect the image element and make sure that the url is correct and the picture can be found on that location. Or share the exact error that you are getting here.

JOHNMAC's avatar

@NAKOV - in inspect element in console it says: Failed to load resource: the server responded with a status of 404 (Not Found) and m getting only product details like price and name not image just default image sign

Nakov's avatar

@AAAA1111 - Does the store method works for you? Can you look in your project public/images/... directory and make sure that when you upload an image the image can be found there? The error says 404 because the image cannot be found, so you need to make sure that you use the correct URL. I assume that the error shows in which location it tries to find the image, so based on that you should check your public folder.

JOHNMAC's avatar

@NAKOV - image is also saving in public/images/... and also showing in admin/view-products but not showing in index.blade.php all paths are correct

Nakov's avatar

@AAAA1111 - sorry, but not having your code to test locally I can't help you much more than what I've already said. I am 100% sure that it is something with the URL used, so inspecting the image element in the index page, and looking at the src after the page has been loaded should give you more info on where to look at. Or just try to use url() helper function instead of the asset() and see if that helps.

jlrdw's avatar

If you use full url does it work.

Please or to participate in this conversation.