如何在 Laravel 中获取已注册路线路径的列表? [英] How to get a list of registered route paths in Laravel?
问题描述
我希望找到一种方法来创建一个数组,其中包含 Laravel 4 中已注册的路由路径.
本质上,我希望得到一个类似这样的列表:
<预><代码>//登录/加入/密码我确实遇到过一个方法 Route::getRoutes()
它返回一个包含路由信息和资源的对象,但路径信息受到保护,我无法直接访问信息.
有没有其他方法可以实现这一目标?也许是一种不同的方法?
Route::getRoutes()
返回一个 RouteCollection
.在每个元素上,您可以执行一个简单的 $route->getPath()
来获取当前路由的路径.
每个受保护的参数都可以通过标准的 getter 获取.
循环是这样工作的:
$routeCollection = Illuminate\Support\Facades\Route::getRoutes();foreach ($routeCollection 作为 $value) {echo $value->getPath();}
I was hoping to find a way to create an array with the registered routes paths within Laravel 4.
Essentially, I am looking to get a list something like this returned:
/
/login
/join
/password
I did come across a method Route::getRoutes()
which returns an object with the routes information as well as the resources but the path information is protected and I don't have direct access to the information.
Is there any other way to achieve this? Perhaps a different method?
Route::getRoutes()
returns a RouteCollection
. On each element, you can do a simple $route->getPath()
to get path of the current route.
Each protected parameter can be get with a standard getter.
Looping works like this:
$routeCollection = Illuminate\Support\Facades\Route::getRoutes();
foreach ($routeCollection as $value) {
echo $value->getPath();
}
这篇关于如何在 Laravel 中获取已注册路线路径的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!