/** * @param $routeName * @param $params * * @return string */ public function __invoke($routeName, array $params = []) { if (false !== strstr($routeName, '@')) { $routeName = explode('@', $routeName); $params['controller'] = $routeName[1]; $routeName = $routeName[0]; } return $this->router->routeNameToUrlString($routeName, $params); }
/** * @param Request $request * @param callable $next * * @return mixed */ public function handle(Request $request, callable $next) { $response = $next($request); if (!$response instanceof Redirect) { return $response; } $url = $this->router->routeNameToUrlString($response->getRouteName(), $response->getParams()); return new RedirectResponse($url, $response->getRedirectionCode()); }
/** * @return null */ public function __invoke() { $table = []; foreach ($this->router->getRoutes() as $item) { $table[] = ['Path' => $item->getPath(), 'Name' => $item->getName(), 'Namespace' => $item->getNamespace(), 'Methods' => implode('|', $item->getAllowedMethods()), 'Middlewares' => $this->router->getMiddlewares($item->getName()) ? implode(', ', $this->router->getMiddlewares($item->getName())) : 'No middlewares']; } $this->climate->out(''); $this->climate->yellow('Routes'); $this->climate->yellowTable($table); $this->climate->out(''); }