@aj411 you definitions.index is using in two different route try to use definitions_another.index for other and then optimize it it will work
Mar 13, 2023
5
Level 1
Laravel project upgraded - issues with artisan optimize
I have recently shifted an old code base to Laravel 9. I am now having an issue when running php artisan optimize. This worked fine in the old version (Laravel 5.8) - It seems that the route name is the issue here but due to the prefix there is no issue in route list (why doesn't it just use the prefixed name as the key?). How do I go about fixing this?
API Route file
Route::prefix('v3')
->middleware(['auth:api', 'throttle:rate_limit,1', 'token.usage', 'trace.request'])
->group(function () {
// Achievements.
Route::apiResource('achievements/definitions', AchievementDefinitionController::class);
// Benefits.
Route::apiResource('benefits/definitions', BenefitDefinitionController::class);
});
Route listing
GET|HEAD api/v3/achievements/definitions ............................................................................................... definitions.index › AchievementDefinitionController@index
POST api/v3/achievements/definitions ............................................................................................... definitions.store › AchievementDefinitionController@store
GET|HEAD api/v3/achievements/definitions/{definition} .................................................................................... definitions.show › AchievementDefinitionController@show
PUT|PATCH api/v3/achievements/definitions/{definition} ................................................................................ definitions.update › AchievementDefinitionController@update
DELETE api/v3/achievements/definitions/{definition} .............................................................................. definitions.destroy › AchievementDefinitionController@destroy
GET|HEAD api/v3/benefits/definitions ....................................................................................................... definitions.index › BenefitDefinitionController@index
POST api/v3/benefits/definitions ....................................................................................................... definitions.store › BenefitDefinitionController@store
GET|HEAD api/v3/benefits/definitions/{definition} ............................................................................................ definitions.show › BenefitDefinitionController@show
PUT|PATCH api/v3/benefits/definitions/{definition} ........................................................................................ definitions.update › BenefitDefinitionController@update
DELETE api/v3/benefits/definitions/{definition} ...................................................................................... definitions.destroy › BenefitDefinitionController@destroy
Optimize error
php artisan optimize
INFO Caching the framework bootstrap files.
config ................................................................................................................................. 10ms DONE
routes .................................................................................................................................. 6ms FAIL
LogicException
Unable to prepare route [api/v3/benefits/definitions] for serialization. Another route has already been assigned name [definitions.index].
at vendor/laravel/framework/src/Illuminate/Routing/AbstractRouteCollection.php:247
243▕ $route->name($this->generateRouteName());
244▕
245▕ $this->add($route);
246▕ } elseif (! is_null($symfonyRoutes->get($name))) {
➜ 247▕ throw new LogicException("Unable to prepare route [{$route->uri}] for serialization. Another route has already been assigned name [{$name}].");
248▕ }
249▕
250▕ $symfonyRoutes->add($route->getName(), $route->toSymfonyRoute());
251▕
+35 vendor frames
36 artisan:35
Please or to participate in this conversation.