在Laravel v4中,我可以使用…
Route::currentRouteName()
我如何在Laravel v5和Laravel v6中做到这一点?
在Laravel v4中,我可以使用…
Route::currentRouteName()
我如何在Laravel v5和Laravel v6中做到这一点?
当前回答
Laravel 5.2可以使用
$request->route()->getName()
它会给你当前的路由名。
其他回答
找到了一种查找当前路由名称的方法,适用于laravel v5, v5.1.28和v5.2.10
名称空间
use Illuminate\Support\Facades\Route;
and
$currentPath= Route::getFacadeRoot()->current()->uri();
对于Laravel Laravel v5.3,你可以使用:
use Illuminate\Support\Facades\Route;
Route::currentRouteName();
使用Laravel 5.1,您可以使用
\Request::route()->getName()
你可以在模板中使用:
<?php $path = Route::getCurrentRoute()->getPath(); ?>
<?php if (starts_with($path, 'admin/')) echo "active"; ?>
你可以使用这行代码:url()->current()
在刀片文件中:{{url()->current()}}
在控制器中访问当前路由名
Ie - http://localhost/your_project_name/edit
$request->segment(1); // edit
(或)
$request->url(); // http://localhost/your_project_name/edit