鍍金池/ 問(wèn)答/PHP/ laravel 如何獲取全部路由數(shù)據(jù) 不要php artisan route:l

laravel 如何獲取全部路由數(shù)據(jù) 不要php artisan route:list

不是要命令行查看 而是要用到這些數(shù)據(jù)

回答
編輯回答
懶洋洋

public function getRouteList()

{
    $app = app();
    $routes = $app->routes->getRoutes();
    foreach ($routes as $k=>$value){
        $path[$k]['uri'] = $value->uri;

        $path[$k]['path'] = $value->methods[0];

    }
    dd($path);
}
2018年8月28日 20:07
編輯回答
浪蕩不羈

其實(shí)找到 php artisan route:list 這個(gè)命令的源碼就行了。

文件位置:\vendor\laravel\framework\src\Illuminate\Foundation\Console\RouteListCommand.php

源碼里包含了你想要的信息

2018年2月10日 14:54