当前位置:网站首页>New routing file in laravel framework

New routing file in laravel framework

2022-06-26 12:22:00 Special sword


Laravel8.x Add a new route file method

  1. Go to the project root directory \app\Providers\RouteServiceProvider.php
  2. stay public function boot() Method to add a new routing file address , Here's the picture
    Route::prefix('merchants/v1_0')      # Prefix 
          ->middleware('api') # middleware 
          ->namespace($this->namespace)
          ->group(base_path('routes/merchants_v1_0.php'));# The path where the new route file is located 
    

 Insert picture description here

Laravel5.x Add a new route file method

  1. Get into Project root \app\Providers\RouteServiceProvider.php In file
  2. Add a custom method in this file mapApiRoutes_v1_0() The method name is defined by itself , My custom name is mapApiRoutes_v1_0
  3. In the custom method **mapApiRoutes_v1_0()** Add the following code to
    /** * api v1.0 Version routing file  */
    protected function mapApiRoutes_v1_0()
    {
          
        Route::prefix('api') # Route prefix ( There can be no )
            ->middleware('api') # middleware 
            ->namespace($this->namespace)
            ->group(base_path('routes/api_v1_0.php')); # Location of the new route file 
    }
    
  4. stay **\app\Providers\RouteServiceProvider.php Find map() Method will be the custom method we just added mapApiRoutes_v1_0()** Add in
    /** * Define the routes for the application. * * @return void */
    public function map()
    {
          
        $this->mapApiRoutes();
    
        $this->mapWebRoutes();
    
        //
        $this->mapApiRoutes_v1_0();#api v1.0 Version routing file  ←←←←← The routing file method we just added 
        $this->mapApiRoutes_v1_1();#api v1.1 Version routing file 
        $this->mapWebApiRoutes_v1_0();#WebApi v1.0 Version routing file 
    }
    

 Insert picture description here

End;

原网站

版权声明
本文为[Special sword]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170522214989.html