问题
In this URL: http://siteName/html/test
I want to catch test
, of course inside the route.
This works great:
Route::get('test', function()
{
return Route::getCurrentRoute()->getPath();
});
But I want to access the path outside of any route and in my route.php
file like this:
// routes.php
return Route::getCurrentRoute()->getPath();
Route::get('test', function()
{
...
});
回答1:
In case you try to catch all routes. Add this as your last route.
Route::any('{all}', function($uri)
{
return Route::getCurrentRoute()->getPath();
})->where('all', '.*');
来源:https://stackoverflow.com/questions/27397487/get-current-path-outside-of-route