laravel路由分割
routes.php/api.php文件用來放置laravel路由,當項目越來越大,相應的路由文件也會越來越多。如果能夠將不同功能的路由分割到不同的文件,那麼對以後的維護將很有幫助。
修改App\Providers\RouteServiceProvider.php 文件
重寫 mapApiRoutes或mapWebRoutes方法
protected function mapApiRoutes()
{
/**
* routes/api分組
*/
foreach(glob(base_path("routes/api/")."*.php")as $file){
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group($file);
}
}