试试这个
Route::getCurrentRoute()->getPath();
或
\Request::route()->getName()
从 v5.1
use Illuminate\Support\Facades\Route;
$currentPath= Route::getFacadeRoot()->current()->uri();
Laravel v5.2
Route::currentRouteName(); //use Illuminate\Support\Facades\Route;
或者如果你需要动作名称
Route::getCurrentRoute()->getActionName();
Laravel 5.2 route documentation
检索请求 URI
path 方法返回请求的 URI。所以,如果传入的请求是针对http://example.com/foo/bar,那么path方法会返回foo/bar:
$uri = $request->path();
is 方法允许您验证传入请求 URI 是否与给定模式匹配。使用此方法时,您可以使用* 字符作为通配符:
if ($request->is('admin/*')) {
//
}
要获取完整的 URL,而不仅仅是路径信息,您可以在请求实例上使用 url 方法:
$url = $request->url();
Laravel v5.3 ... v5.8
$route = Route::current();
$name = Route::currentRouteName();
$action = Route::currentRouteAction();
Laravel 5.3 route documentation
Laravel v6.x...7.x
$route = Route::current();
$name = Route::currentRouteName();
$action = Route::currentRouteAction();
** 截至 2019 年 11 月 11 日 - 版本 6.5 **
Laravel 6.x route documentation
有一个选项可以使用请求获取路由
$request->route()->getName();