router = $router; } /** * Execute the console command. * * @return int */ public function handle() { $routes = $this->buildRoutesArray(); $json = $routes->toJson(); file_put_contents(config('routes.target'), $json); $this->info(sprintf('Routes successfully generated in %s', config('routes.target'))); $this->comment("Don't forget to rebuild assets using npm run dev or npm run prod !"); return 0; } /** * Return a list of whitelisted routes as a Laravel Collection. * * @return \Illuminate\Support\Collection */ protected function buildRoutesArray() { $routes = []; $whitelist = config('routes.whitelist'); foreach ($this->router->getRoutes() as $route) { if (!in_array($route->getName(), $whitelist)) { continue; } $routes[$route->getName()] = $route->uri(); } return collect($routes); } }