Generating an HTML Image Element


You want to add an image to your Blade template.

Instead of simply using the <img...> HTML tag, you want to use the HTML facade.


Use the HTML::image() method.

The only required argument is the path to the image.

{{ HTML::image('img/picture.jpg') }}

Which produces the following HTML.

<img src="http://your.url/img/picture.jpg">

If the image path you pass isn't a complete URL, Laravel will use your application's URL to build a complete URL.

You can add the alt attribute with the second argument.

{{ HTML::image('img/picture.jpg', 'a picture') }}

Now the HTML will look like the following.

<img src="http://your.url/img/picture.jpg" alt="a picture">

The third argument, if used, must be an array. It contains additional attributes to add to the img tag.

{{ HTML::image('img/picture.jpg', 'a picture', array('class' => 'thumb')) }}

Now the HTML contains a class attribute.

<img src="http://your.url/img/picture.jpg" class="thumb" alt="a picture">


Nothing to discuss.

comments powered by Disqus