当使用auth中间件时,artisan命令会发生错误,因为没有HTTP请求。因此,我们可以使用以下代码在artisan命令中手动构造请求:
getRoutes())->map(function ($route) {
return [
'method' => implode('|', $route->methods()),
'uri' => $route->uri(),
'name' => $route->getName(),
'action' => ltrim($route->getActionName(), '\\')
];
});
$headers = ['Method', 'URI', 'Name', 'Action'];
$this->table($headers, $routes);
}
protected function callCommand($command, $parameters = [])
{
$request = Request::create('artisan '.$command, 'GET');
$this->laravel->make('Illuminate\Contracts\Http\Kernel')
->handle($request);
}
}
使用此代码,您可以在终端中使用'php artisan route:list”命令并在终端中获取所有路由列表,同时可以在其中包含具有auth中间件的路由。