Link with icon in Laravel 4

痞子三分冷 提交于 2019-12-03 12:45:01

I'd just put the link in the href.

<a href="{{ url('/') }}"><span><i class="icon-home"></i></span> Home</a>

No need to generate all the rest through Laravel.

What @Dries suggests is simple and very straightforward, but you really want to have it done entirely via Laravel, I would suggest writing a HTML macro, especially if you want more complex html structures to be involved. For example, here is a macro for <a><img /></a> structure:

    HTML::macro('image_link', function($url = '', $img='img/', $alt='', $param = false, $active=true, $ssl=false)
{
    $url = $ssl==true ? URL::to_secure($url) : URL::to($url);  
    $img = HTML::image($img,$alt);
    $link = $active==true ? HTML::link($url, '#', $param) : $img;
    $link = str_replace('#',$img,$link);
    return $link;
}); 

You could read more about it here: http://forums.laravel.io/viewtopic.php?pid=10467

Rajeev Dambal
{!! HTML::decode(link_to(URL::previous(),
    '<i class="fa fa-chevron-left" aria-hidden="true"></i> Back',
    ['class' => 'btn btn-primary'])) !!}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!