laravel搭建项目的时候可以多个项目在一个框架内,例如:后台、前台、接口
默认是全部访问\app\Http\Controllers下的文件。
但是写在一起很混乱,所以可以分目录管理多个项目。
\App\Providers\RouteServiceProvider.PHP
这个文件里面是设置路由访问命名空间的。
我这里是这样设置的
protected $namespace = 'App\Http\Controllers'; //前台逻辑访问命名空间
protected $apinamespace = 'App\Api\Controllers';//新增API访问的命名空间
/**
* 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'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapApiRoutes()
{
Route::prefix('api')
->middleware('api')
->namespace($this->apinamespace)
->group(base_path('routes/api.php'));
}
这样就可以实现一个框架多个项目管理的方法