Search code examples
phplaravellaravel-5laravel-5.3

Img not displaying when route is changed in laravel


I have an image tag

<img src="uploads/store/products/1-1486038295-1-1-qYv3f.png" class="img-responsive" style="width:100%; height: 100%;" alt="asdasd asd">

It is displayed when the url in web.php is

Route::get('/product', 'FlashCartController@find_product');

But when I change it to

Route::get('/product/search', 'FlashCartController@find_product');

Image doesn't display. What is the error or issue behind it?


Solution

  • I belive you should not be using static paths, "uploads/store/.." If it is a static image ( used to design or something front end) it should be under the public folder, for example

    1. Save image in "/public/uploads/store/products/1-1486038295-1-1-qYv3f.png"
    2. (Use this to retrieve image) src="{{URL::asset('uploads/store/products/1-1486038295-1-1-qYv3f.png')}}"

    If it is an image to be changed in some sort of backoffice, then you should probably look at the storage docs ( https://laravel.com/docs/5.4/filesystem )