better performance than route cache

Submitted by icfr - 8 years ago

symply dont register unessecary route you dont have to use facade, $router instance is set by the function in route provider with config cached and files compiled i get app booted in ~30ms vs ~50 on my dev server

     /** in my RouteserviceProvider
     *
     *
     * Define the routes for the application.
     *
     * @param  \Illuminate\Routing\Router  $router
     * @return void
     */
    public function map(Router $router, Request $request)
    {
        $router->group(['namespace' => $this->namespace], function ($router) use ($request) {
            //to get route:list 
            $isCommand = $this->app->runningInConsole();
            $prefix = $request->segment(1);
            require app_path('Http/routes.php');
            if ($prefix == 'admin' || $isCommand) {
                $router->group(['prefix' => 'admin'], function ($router) use ($isCommand, $request) {
                   // with this you can split the route  file
                   require app_path('Http/AdminRoutes.php');
                });
            }
        });
    }
    
    //in my route files
if ($prefix == '' || $isCommand) {
    $router->get('/', 'HomeController@index');
}

if ($prefix == 'posts' || $isCommand) {
    $router->ressource('posts', 'PostController');
}