get current path outside of Route

安稳与你 提交于 2019-12-11 12:14:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!