Laravel: better performance than route cache

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

01
     /** in my RouteserviceProvider
02
     *
03
     *
04
     * Define the routes for the application.
05
     *
06
     * @param  \Illuminate\Routing\Router  $router
07
     * @return void
08
     */
09
    public function map(Router $router, Request $request)
10
    {
11
        $router->group(['namespace' => $this->namespace], function ($router) use ($request) {
12
            //to get route:list
13
            $isCommand = $this->app->runningInConsole();
14
            $prefix = $request->segment(1);
15
            require app_path('Http/routes.php');
16
            if ($prefix == 'admin' || $isCommand) {
17
                $router->group(['prefix' => 'admin'], function ($router) use ($isCommand, $request) {
18
                   // with this you can split the route  file
19
                   require app_path('Http/AdminRoutes.php');
20
                });
21
            }
22
        });
23
    }
24
    

01
    //in my route files
02
if ($prefix == '' || $isCommand) {
03
    $router->get('/', 'HomeController@index');
04
}
05
 
06
 
07
 
08
if ($prefix=='posts' || $isCommand) {
09
    $router->ressource('posts', 'PostController');
10
}
11