@metalcoder You’re going to struggle given that routes need the corresponding controller specifying:
Route::apiResource('/v1/users', 'App\Http\Controllers\Api\V1\UserController');
You can’t really say “Use this controller class if it exists, and if not fall back to this other controller. That’s just not how Laravel routes work. Especially given controllers are instantiated when the app is booted.
So unfortunately, if your API design wasn’t great that you need to make a version two, then you also need to create the controllers to handle those v2 endpoints. There’s nothing stopping you from extending the v1 controller classes if there are no changes, though:
namespace App\Http\Controllers\Api\V2;
use App\Http\Controllers\Api\V1\UserController as V1UserController;
class UserController extends V1UserController
{
}
Route::prefix('v1')->group(function () {
Route::apiResource('users', 'App\Http\Controllers\Api\V1\UserController');
});
Route::prefix('v2')->group(function () {
Route::apiResource('users', 'App\Http\Controllers\Api\V2\UserController');
});