Search code examples
laravellaravel-5.3laravel-routinglaravel-5.4

Laravel 5.3 and 5.4 Custom Route File


According to the Laravel Documentation, in routing section, the files located in the route directory are automatically loaded by the framework.

All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by the framework.

So, I tried to create another file in this directory called auth.php for handling my custom authentication routes. But, the routes defined in this file are not loaded.

It is possible to use this approach, or I need to register a service provider to load custom route files?


Solution

  • You need to map routes in your RouteServiceProvider.php, Check the example of web routes.

       /**
         * Define the "web" routes for the application.
         *
         * These routes all receive session state, CSRF protection, etc.
         *
         * @return void
         */
        protected function mapWebRoutes()
        {
            Route::group([
                'middleware' => 'web',
                'namespace' => $this->namespace,
            ], function ($router) {
                require base_path('routes/web.php');
            });
        }