I have a Laravel 8.40 backend with many routes, and when I was adding scribe to the project I realized that many routes are twice listed.
Calling php artisan route:list
as example, it will duplicate the route api/hq/v1/account/login
, removing the v1/account
portion:
POST api/hq/login login AppHttpControllersHqAccount@logIn
POST api/hq/v1/account/login login AppHttpControllersHqAccount@logIn
I want to have just api/hq/v1/account/login
.
routes/api.php
Route::group(['prefix' => 'hq'], function(){
includeRouteFiles(__DIR__.'/api/hq/');
});
routes/api/hq/index.php
Route::group(['prefix' => 'v1'], function(){
Route::group(['prefix' => 'account'], function(){
includeRouteFiles(__DIR__ . '/account/');
});
});
routes/api/hp/account/index.php
Route::post('/login', [Account::class, 'logIn'])->name('login');
Already ran php artisan route:clear
.
…
How can I fix it?
Thank you all in advance!
2
Answers
includeRouteFiles
is a helper method from laravel-boilerplate that uses RecursiveDirectoryIterator to get the list of route files to be included.If you call
includeRouteFiles
in a route file that is already being included by the same method, you’ll load its routes twice.You can try change this.
Into
Note
Answer is based on Organizing your routes