Laravel:URL :: route()仅打印没有网站名称的路由链接

Rad*_*duS 1 laravel laravel-4

我有这条路

Route::get('/dashboard', array(
            'as' => 'dashboard-get',
            'uses' => 'AppController@getDashboard'
));
Run Code Online (Sandbox Code Playgroud)

在视图中,如果我写

<a href="{{ URL::route('dashboard-get') }}">Dashboard</a>
Run Code Online (Sandbox Code Playgroud)

它将返回整个链接.

http://192.168.0.1/dashboard
Run Code Online (Sandbox Code Playgroud)

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

/dashboard
Run Code Online (Sandbox Code Playgroud)

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

Raz*_*zor 7

代码源,route方法默认生成绝对URL,您可以将其设置为false:

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

更新

您还可以通过定义自己的自定义链接

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

然后调用你的宏

{{ HTML::Rlinks('dashboard-get',array(),'Dashboard') }}
Run Code Online (Sandbox Code Playgroud)