在Laravel v4中,我可以使用…

Route::currentRouteName()

我如何在Laravel v5和Laravel v6中做到这一点?


当前回答

您可以使用以下方法:

Route::getCurrentRoute()->getPath();

在Laravel版本> 6.0中,您可以使用以下方法:

$route = Route::current();

$name = Route::currentRouteName();

$action = Route::currentRouteAction();

其他回答

在larvel 5.3中,我用它来获取路由名

要求::路径()

如果你需要url,而不是路由名,你不需要使用/需要任何其他类:

url()->current();

有很多方法可以做到这一点。你可以输入:

\Illuminate\Support\Facades\Request::route()->getName()

获取路由名称。

你可以使用下面的代码在刀片文件中获取路由名称

request()->route()->uri

在控制器中访问当前路由名

Ie - http://localhost/your_project_name/edit

$request->segment(1);  // edit

(或)

$request->url();  // http://localhost/your_project_name/edit