Clone the Laravel router and set the middleware on the cloned router.

@return \Illuminate\Routing\Router
763470
protected function cloneLaravelRouter()
    {
        $router = clone $this->app['router'];
        $router->aliasMiddleware('api.auth', NodesHttpMiddlewareAuth::class);
        $router->aliasMiddleware('api.controllers', NodesHttpMiddlewarePrepareController::class);
        $router->aliasMiddleware('api.throttle', NodesHttpMiddlewareRateLimit::class);
        $router->aliasMiddleware('api.useragent', NodesHttpMiddlewareUserAgent::class);
        $router->aliasMiddleware('api.meta', NodesHttpMiddleware::class);

        return $router;
    }
1201491
private static function init_routing()
    {
        static::$container->add_singleton(
            Router::class,
            function () {
                return new Router();
            }
        );

        static::$container->add_singleton(
            Request::class,
            function () {
                return new Request();
            }
        );

        static::$container->add_singleton(
            Response::class,
            function () {
                return new Response();
            }
        );

        static::$container->add_singleton(
            Validator::class,
            function () {
                return new Validator();
            }
        );

        static::$container->alias(Router::class, 'router');
        static::$container->alias(Request::class, 'request');
        static::$container->alias(Response::class, 'response');
    }
987519
public static function all()
    {
        $router = new AltoRouter();

        foreach (static::$routes as $route) {
            isset($route['name']) ? $name = $route['name'] : $name = null;
            $router->map($route['method'], $route['target'], $route['handler'], $name);
        }

        return $router;
    }
1167655
public function getRouter() : RouterInterface
    {
        if (! $this->router instanceof RouterInterface) {
            $router = new Router();
            $resolver = $this->getCallbackResolver();
            if ($resolver instanceof CallbackResolverInterface) {
                $router->setCallbackResolver($resolver);
            }

            $routerCacheFile = $this->getConfiguration('routerCacheFile', false);
            if ($routerCacheFile) {
                $router->setCacheFile($routerCacheFile);
            }

            $this->router = $router;
        }

        return $this->router;
    }
1262545
private function initRouter(): App
    {
        $request = $this->container('request');
        $response = $this->container('response');
        $router = new Router($request, $response);
        $router->error(Error::class);

        $this->containers()->set('router', $router);
        return $this;
    }
1166210
function GetRouter()
	{
		if ($this->router == null)
		{
			require_once("verysimple/Phreeze/GenericRouter.php");
			$this->router = new GenericRouter(self::$ROOT_URL,self::GetDefaultAction(),self::$ROUTE_MAP);
		}
		return $this->router;
	}
254981
public function setMiddleware($middleware) : self
    {
        if (is_string($middleware)) {
            $middleware = [$middleware];
        }
        $this->middleware = collect()->merge($middleware);
        return $this;
    }
555690
protected function registerMiddleware()
    {
        $this->app->singleton(Request::class, function ($app) {
            $middleware = new Middleware\Request(
                $app,
                $app[ExceptionHandler::class],
                $app[Router::class],
                $app[RequestValidator::class],
                $app['events']
            );

            $middleware->setMiddlewares($this->config('middleware', false));

            return $middleware;
        });

        $this->app->singleton(AuthMiddleware::class, function ($app) {
            return new Middleware\Auth($app[Router::class], $app[Auth::class]);
        });

        $this->app->singleton(RateLimit::class, function ($app) {
            return new Middleware\RateLimit($app[Router::class], $app[Handler::class]);
        });

        $this->app->singleton(PrepareController::class, function ($app) {
            return new Middleware\PrepareController($app[Router::class]);
        });
    }
223592
public function build() : RouterInterface
    {
        $router = $this->router;
        try{
            foreach($this->modules as $module)
            {
                $module->install($router);
            }
        }
        catch(\Throwable $e)
        {
            throw new RouterBuildingException($e);
        }
        return $router;
    }
767273
public function map()
    {
        Route::namespace($this->namespace)->group(function (Router $router) {

            /*
             * Front office routes
             */
            if ($page = TypiCMS::getPageLinkedToModule('news')) {
                $router->middleware('public')->group(function (Router $router) use ($page) {
                    $options = $page->private ? ['middleware' => 'auth'] : [];
                    foreach (locales() as $lang) {
                        if ($page->translate('status', $lang) && $uri = $page->uri($lang)) {
                            $router->get($uri, $options + ['uses' => 'PublicController@index'])->name($lang.'::index-news');
                            $router->get($uri.'.xml', $options + ['uses' => 'PublicController@feed'])->name($lang.'::news-feed');
                            $router->get($uri.'/{slug}', $options + ['uses' => 'PublicController@show'])->name($lang.'::news');
                        }
                    }
                });
            }

            /*
             * Admin routes
             */
            $router->middleware('admin')->prefix('admin')->group(function (Router $router) {
                $router->get('news', 'AdminController@index')->name('admin::index-news')->middleware('can:see-all-news');
                $router->get('news/create', 'AdminController@create')->name('admin::create-news')->middleware('can:create-news');
                $router->get('news/{news}/edit', 'AdminController@edit')->name('admin::edit-news')->middleware('can:update-news');
                $router->post('news', 'AdminController@store')->name('admin::store-news')->middleware('can:create-news');
                $router->put('news/{news}', 'AdminController@update')->name('admin::update-news')->middleware('can:update-news');
            });

            /*
             * API routes
             */
            $router->middleware('api')->prefix('api')->group(function (Router $router) {
                $router->middleware('auth:api')->group(function (Router $router) {
                    $router->get('news', 'ApiController@index')->middleware('can:see-all-news');
                    $router->patch('news/{news}', 'ApiController@updatePartial')->middleware('can:update-news');
                    $router->delete('news/{news}', 'ApiController@destroy')->middleware('can:delete-news');

                    $router->get('news/{news}/files', 'ApiController@files')->middleware('can:update-news');
                    $router->post('news/{news}/files', 'ApiController@attachFiles')->middleware('can:update-news');
                    $router->delete('news/{news}/files/{file}', 'ApiController@detachFile')->middleware('can:update-news');
                });
            });
        });
    }
141554
public function & GetRouter () {
		if ($this->router === NULL) {
			$routerClass = $this->routerClass;
			$this->router = & $routerClass::GetInstance();
		}
		return $this->router;
	}
50258
protected function registerRouter()
    {
        $this->app->singleton('router', function ($app) {
            return new Router($app['events'], $app['actions'], $app);
        });

        $this->app['actions']->listen('init', function () {
            if (is_admin()) {
                app('url')->forceRootUrl(env('APP_URL'));
            }
        });

        $this->disableRedirectionOnRegisteredRoutes();
    }
1354164
private function routeManager()
    {
        if (!isset($this->routeManager)) {
            $config = $this->config();
            $routesConfig = (isset($config['routes']) ? $config['routes'] : [] );

            $this->routeManager = new RouteManager([
                'config' => $routesConfig,
                'app'    => $this
            ]);
        }

        return $this->routeManager;
    }
675762
public function getRouter()
    {
        if (is_null($this->_router)) {
            $this->_router = new Router($this);
        }
        return $this->_router;
    }
169069
protected function buildRouter()
    {
        $routes = new RouteCollection();
        $context = new RequestContext();
        $router = new UrlMatcher($routes, $context);

        return($router);
    }
732398
public function route()
    {
        if (!$this->route)
        {
            if (php_sapi_name() === 'cli')
            {
                global $argv;
                $this->route = $this->router
                    ->getRoute($argv[1] ?? null, 'console', 'cli');
            }
            else
            {
                $this->route = $this->router
                    ->getRoute($this->urlPath(), $this->domain(), $this->scheme());
            }
        }

        return $this->route;
    }
601922
protected function registerMiddleware()
    {
        $this->app->singleton(NodesHttpMiddlewareRequest::class, function ($app) {
            $middleware = new NodesHttpMiddlewareRequest(
                $app,
                $app['api.exception'],
                $app['api.router'],
                $app['api.http.validator'],
                $app['events']
            );
            $middleware->setMiddlewares(config('nodes.api.middleware', []));

            return $middleware;
        });

        $this->app->singleton(NodesHttpMiddlewareAuth::class, function ($app) {
            return new NodesHttpMiddlewareAuth($app['api.router'], $app['api.auth']);
        });

        $this->app->singleton(NodesHttpMiddlewareRateLimit::class, function ($app) {
            return new NodesHttpMiddlewareRateLimit($app['api.router'], $app['api.limiting']);
        });

        $this->app->singleton(NodesHttpMiddlewarePrepareController::class, function ($app) {
            return new NodesHttpMiddlewarePrepareController($app['api.router']);
        });
    }