multiple route file instead of one main route file in laravel 5

前端 未结 9 1109
广开言路
广开言路 2020-12-15 12:58

I am a novice in web developing with Laravel 5. I installed asGgardCMS and After seeing asgardCms codes, I found that there is nothing codes in app/Http/route.php file and r

9条回答
  •  失恋的感觉
    2020-12-15 13:27

    laravel ^6

    explained in comments

    mapApiRoutes();
    
            $this->mapWebRoutes();
    
        // map new custom routes
            $this->mapCustomRoutes();
        }
    
        /**
         * Define the "web" routes for the application.
         *
         * These routes all receive session state, CSRF protection, etc.
         *
         * @return void
         */
        protected function mapWebRoutes()
        {
            Route::middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));
        }
    
        /**
         * Define the "api" routes for the application.
         *
         * These routes are typically stateless.
         *
         * @return void
         */
        protected function mapApiRoutes()
        {
            Route::prefix('api')
                ->middleware('api')
                ->namespace($this->namespace)
                ->group(base_path('routes/api.php'));
        }
    
       /**
         * Define the "custom" routes for the application.
         *
         * These routes are typically stateless.
         *
         * @return void
         */
        protected function mapCustomRoutes()
        {
               Route::middleware('web')
                ->namespace($this->custom_namespace)  //or change its custom_namespace to namespace if you don't need change diractory of your controllers  
                ->group(base_path('routes/custom.php')); // change custom.php to your custom routers file name
        }
    }
    

提交回复
热议问题