如何在 Laravel 中获取已注册的路由路径列表? [英] How to get a list of registered route paths in Laravel?
问题描述
我希望找到一种方法来创建一个包含 Laravel 4 中已注册路由路径的数组.
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
我确实遇到了一个方法 Route::getRoutes()
,它返回一个包含路由信息和资源的对象,但路径信息受到保护,我无法直接访问信息.
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()
返回一个 RouteCollection
.在每个元素上,您可以执行一个简单的 $route->getPath()
来获取当前路由的路径.
Route::getRoutes()
returns a RouteCollection
. On each element, you can do a simple $route->getPath()
to get path of the current route.
每个受保护的参数都可以通过标准 getter 获取.
Each protected parameter can be get with a standard getter.
循环的工作方式如下:
$routeCollection = IlluminateSupportFacadesRoute::getRoutes();
foreach ($routeCollection as $value) {
echo $value->getPath();
}
这篇关于如何在 Laravel 中获取已注册的路由路径列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!