Laravel分割路由为多个文件

在routes下面新建web目录,将原来的web.php拆分为多个文件,名称可根据功能来命名

修改app/Providers/RouteServiceProvider.php文件的mapWebRoutes方法

    /**
     * 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'));
        Route::middleware('web')
             ->namespace($this->namespace)
             ->group(function(){
                 $webRouteFiles = \File::files(base_path('routes\web'));
                 foreach ($webRouteFiles as $f){
                     require_once $f->getRealPath();
                 }
             });
    }
Last modification:March 7th, 2021 at 12:05 pm
哎呀呀,大家随意,随意就好!