I ended up using namespaces and direct或ies under app/controllers:
/app
/controllers
/Api
/v1
/UserController.php
/v2
/UserController.php
And in UserController.php files I set the namespace acc或dingly:
namespace Api\v1;
或
namespace Api\v2;
然后在我的路由上,我做了这样的事情:
Route::group(['prefix' => 'api/v1'], function () {
Route::get('user', 'Api\v1\UserController@index');
Route::get('user/{id}', 'Api\v1\UserController@show');
});
Route::group(['prefix' => 'api/v2'], function () {
Route::get('user', 'Api\v2\UserController@index');
Route::get('user/{id}', 'Api\v2\UserController@show');
});
我不确定这是最好的解决方案.然而,它允许以不相互干扰的方式对控制器进行版本控制.如果需要的话,你可以用模型做一些类似的验证.