Laravel5.5添加新路由文件并制定规则

在Laravel中,如果我们需要自定义路由,例如把app/Http/routes.php文件被移动到routes目录下,并且分割成两个文件:web.php和api.php。
可以修改App\Providers\RouteServiceProvider文件,

<?php


namespace App\Providers;


use Illuminate\Support\Facades\Route;

use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;


class RouteServiceProvider extends ServiceProvider

{

    protected function mapWebRoutes()

    {

        Route::middleware('web')

             ->namespace($this->namespace)

             ->group(base_path('routes/web.php'));


        Route::middleware('web')

            ->namespace($this->namespace)

            ->group(base_path('routes/test.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'));

    }


}