Reputation: 1222
I created 2 route groups in my api route file, and I can't access to routes of second group.
First group :
$api = app('Dingo\Api\Routing\Router');
$request = app('\Dingo\Api\Http\Request');
$api->dispatch($request);
/* API V1 ROUTES */
$prefix = 'test';
$api->group(['prefix' => $prefix,'version'=> 'v1'],function($api) {
$api->post('/entity/validate/{code}', [
'as' => 'validate.code',
'uses' => 'App\Http\Controllers\XXX\Api\SmsController@validateCodeV1',
]);
});
This is working perfectly and I reach my function validateCodeV1 that does perfectly its job. On another side I have right after it Second group :
$prefix = 'testv2';
$api->group(['prefix' => $prefix,'version'=> 'v2'],function($api) {
$api->post('/entity/validate/{code}', [
'as' => 'validate.code',
'uses' => 'App\Http\Controllers\XXX\Api\SmsController@validateCode',
]);
});
Here I have a 404 when I try to call my api with a prefix testv2/entity/validate/XXX
I don't know how I can specify properly my prefix to swap from my v1 route to my v2 route... I use Laravel 5.5
EDIT : check of routes contains only one of my 2 routes, even after cache clear :
php artisan route:list | grep entity/validate
| | POST | /test/entity/validate/{code} | validate.code | Closure | api.controllers |
Upvotes: 0
Views: 290
Reputation: 1222
I fixed it by mixing the 2 solutions of this post : Dingo API - How to add version number in url? It is not exactly a duplicate so I let my post, but if someone think it is appropriated to remove my post just ask and I will do it
Upvotes: 0
Reputation: 39
I've tried your code and change the $api-> to Route:: and both work as they should and listed in php artisan route:list.
$prefix = 'test';
Route::group(['prefix' => $prefix,'version'=> 'v1'],function($api) {
Route::post('/entity/validate/{code}', [
'as' => 'validate.code',
'uses' => 'App\Http\Controllers\XXX\Api\SmsController@validateCodeV1',
]);
});
$prefix = 'testv2';
Route::group(['prefix' => $prefix,'version'=> 'v2'],function($api) {
Route::post('/entity/validate/{code}', [
'as' => 'validate.code',
'uses' => 'App\Http\Controllers\XXX\Api\SmsController@validateCode',
]);
});
I think, you can check your $api or $request, maybe there is an error, function, or something else that only allow v1 version.
Upvotes: 1