Creating Image link with HTML Helper Creating Image link with HTML Helper laravel laravel

Creating Image link with HTML Helper


I think it's overkill for no reason.I would do:

<a href="#"><img src={{asset('img/logo.png')}} alt="Logo"></a>

If I then need a dynamic link in place of the #, I would do:

<a href="{{URL::to('/')}}"><img src={{asset('img/logo.png')}} alt="Logo"></a>

Try to use html as much as you can.


You probably will have to:

<a href="#">{{ HTML::image("img/logo.png", "Logo") }}</a>

Because, link() uses entities to escape the title:

public function link($url, $title = null, $attributes = array(), $secure = null){    $url = $this->url->to($url, array(), $secure);    if (is_null($title) or $title === false) $title = $url;    return '<a href="'.$url.'"'.$this->attributes($attributes).'>'.$this->entities($title).'</a>';}

Producing this source code:

"<a href="#"><img src="http://localhost/img/logo.png" alt="Logo"></a>"


You could also use html_entity_decode to get your code working

{{ html_entity_decode( HTML::link("#", HTML::image("img/logo.png", "Logo") ) ) }}