1
votes

I have encountered a lot of difficulty whilst getting images to display on a localhost server using Laravel 4.2.6 in a Blade Template View.

My image: 'logo.png' has been stored in the laravel\public\ folder for simplicity (laravel\public\logo.png).

I have a 'base.blade.php' view stored in app\views\layouts.

  <body>
     <p> Image goes here
         {{ HTML::image('logo.png', 'logo') }}
         <img src="{{ asset('logo.png') }}" alt="logo" />
     </p>
     @yield('body')
  </body>

Neither of the above methods for displaying the image have worked. Rather they display a broken image icon.

I thought adding an initial '/' to the route may help point to the root directory, but this hasn't helped either:

         {{ HTML::image('/logo.png', 'logo') }}
         <img src="{{ asset('/logo.png') }}" alt="logo" />

I initially tried storing the image as public/assets/images/logo.png, but changed the directory to simplify the problem when encountering errors.

I can't see a reason for this not to work. I am new to using Laravel, but have searched thoroughly and found no other solutions than those above. I have considered that perhaps I have some configuration wrong in WAMP, the rewrite_module is in use however. Do I need to declare an asset in routes before I use it? Is there something in the Laravel configuration I need to change?

Any help would be greatly appreciated!

1
If you look at the source, where does the links for images go?peter.babic
re check the image is it stored in public if file is in public <img src="{{asset('logo.png')}}" alt="logo" > should workArun Kumar
I managed to fix this problem, using WAMP the public folder was C:/wamp/www rather than C:/wamp/www/laravel/public. Is there a way to change this to default to laravel/public?Arcanewinds
I was able to change the public folder to default from C:/wamp/www by editing the configuration file 'httpd' within apache/conf. The field DocumentRoot was changed to: "c:/wamp/www/laravel/public". Hopefully this can help anyone else who encounters this problem, probably down to misinstallation!Arcanewinds

1 Answers

0
votes

The default root folder is defined in the httpd file, found in the Apache/conf directory.

The laravel public folder can be assigned as the root folder by altering the 'DocumentRoot' field in the Apache httpd.conf file (found in C:\wamp\bin\apache\apache2.4.9\conf in this case), to:

DocumentRoot "c:/wamp/www/laravel/public"