Laravel:URL :: route()仅打印路线链接,而不显示网站名称 [英] Laravel: URL::route() print only the route link without the website name

查看:63
本文介绍了Laravel:URL :: route()仅打印路线链接,而不显示网站名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这条路线

Route::get('/dashboard', array(
            'as' => 'dashboard-get',
            'uses' => 'AppController@getDashboard'
));

如果我在视图中写

<a href="{{ URL::route('dashboard-get') }}">Dashboard</a>

它将返回我整个链接.

http://192.168.0.1/dashboard

如何在VIEW中按名称获取路线并仅打印

How can get the route by name in the VIEW and only print the

/dashboard

没有链接的http://192.168.0.1/部分

推荐答案

来自

From the code source, route method generate an absolute URL by default, you may set it to false:

<a href="{{ URL::route('dashboard-get',array(),false) }}">Dashboard</a>

更新

您还可以通过

HTML::macro('Rlinks',function($routeName,$parameters = array(),$name){ 
    return "<a href=".substr(URL::route($routeName,$parameters,false), 1) .">"
       .$name.
    "</a>";
});

然后调用您的宏

{{ HTML::Rlinks('dashboard-get',array(),'Dashboard') }}

这篇关于Laravel:URL :: route()仅打印路线链接,而不显示网站名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆