Laravel 在视图中列出路由
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43537706/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel list routes in the view
提问by Micheasl
How can I list routes specifically the api routes in my view?
如何在我的视图中专门列出 api 路由?
For example These:
例如这些:
...api/user
...api/Information
The artisan command for example does list them like this:
例如, artisan 命令确实会像这样列出它们:
php artisan route:list
回答by Pankit Gami
In your controller you can get the list of routes using Artisan
facade. I assume all your api
routes have api
string in its path.:
在您的控制器中,您可以使用Artisan
Facade获取路由列表。我假设您的所有api
路线api
在其路径中都有字符串。:
public function showRoutes($request) {
$routes = Artisan::call('route:list', ['--path' => 'api']);
return view('your_view', compact('routes'));
}
Edit :
编辑 :
You can also use Route
facades getRoutes
method.
您也可以使用Route
FacadesgetRoutes
方法。
$routes = [];
foreach (\Route::getRoutes()->getIterator() as $route){
if (strpos($route->uri, 'api') !== false){
$routes[] = $route->uri;
}
}
return view('your_view', compact('routes'));