Creating Image link with HTML Helper

删除回忆录丶 提交于 2019-12-03 14:08:08

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="#">&lt;img src=&quot;http://localhost/img/logo.png&quot; alt=&quot;Logo&quot;&gt;</a>"

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 could also use html_entity_decode to get your code working

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

HTML helper has been removed from Laravel 5

now you could simple use this

<img src="{{ asset('logo.png') }}" alt="logo">

This asset by default point to public folder of your larval application

Additional to correct answer also you can add some attribute like height and width

<a href="#">{{ HTML::image("img/logo.png", "Logo",array('height'=>'100','width'=>'100')) }}</a>
\Html::tag('a', \Html::image('image path')->toHtml(), ['href' => 'link']);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!