I'm running laravel application and recently i have added new api routes in api.php
for new functionality
consider below is my route :
Route::get('/testdb', 'Controller@testDb');
when i am trying to run the above api, getting 404 NOT FOUND
for all the new routes
I have cleared all the cache and routes.
Here is api.php code
Route::group(['prefix' => 'v1', 'namespace' => 'Api', 'middleware' => 'dbchange'], function () {
Route::get('/testdb', 'Controller@testDb');
}
URL : https://domain/api/v1/testdb
I have tried provided solution available on the stackoverflow but none of them is worked in my case
CodePudding user response:
To change that you can head over to the file, app/providers/RouteServiceProviders.php
and change prefix to what ever name you would like in the mapApiRoutes()
function.
But there is a catch in everything you change. The order of the prefix should be written as shown in the following code, if you want to use your API routes with and without prefixes.
protected function mapApiRoutes(){
Route::prefix('{locale}/api') //----Prefixed route here
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::prefix('api')
->middleware('api') //----Un-prefixed route here
->namespace($this->namespace)
->group(base_path('routes/api.php'));
}
In any multiple API prefixed scenarios such as,prefix(‘{locale}/api’)
the additional prefixed route has to be registered above the default prefix route. This way you can access an API with the prefix and without the prefix.
CodePudding user response:
Use this in Route::group namespace
'namespace' => 'Api\v1'