问题
I have this route
Route::get('/dashboard', array(
'as' => 'dashboard-get',
'uses' => 'AppController@getDashboard'
));
In the View if i write
<a href="{{ URL::route('dashboard-get') }}">Dashboard</a>
It will return me the entire link.
http://192.168.0.1/dashboard
How can get the route by name in the VIEW and only print the
/dashboard
Without the http://192.168.0.1/
part of the link
回答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>
Update
You can also define your own custom links by
HTML::macro('Rlinks',function($routeName,$parameters = array(),$name){
return "<a href=".substr(URL::route($routeName,$parameters,false), 1) .">"
.$name.
"</a>";
});
Then call your macro
{{ HTML::Rlinks('dashboard-get',array(),'Dashboard') }}
回答2:
You may try something like this:
app('router')->getRoutes()->getByName('dashboard-get')->uri();
来源:https://stackoverflow.com/questions/26205114/laravel-urlroute-print-only-the-route-link-without-the-website-name