laravel版本是 5.4.36(使用命令 php artisan --version查看),项目中本来只有一个routes.php(路径是app/Http/routes.php),现在想要建多个路由文件,为了便于管理路由。
可以分三步完成:
1、在项目根目录下创建一个routes文件夹,下面再分别建立两个文件web.php和api.php,结构如下:
2、以api.php文件为例,在app/Providers/RouteServiceProvider.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'));
}
修改本文件中的map方法(添加一句话):