Laravel 7.x - artisan route:cache always generates a different file ? #33963
-
Hello, Part of my personal workflow is that before git pushing my changes, I always automatically regenerate the route cache file with
But the generated cache file bootstrap/cache/routes-v7.php is always generated differently, even when there is no change in the routes. I do not want this, if the routes don't change, the file should be exactly the same. P.S. this way I never can forget to update the cached routes. If I have to manually cache the routes after a change that is very error prone. Reproduction
InvestigationThe diff of bootstrap/cache/routes-v7.php shows lots of differences for
So I found the /**
* Get a randomly generated route name.
*
* @return string
*/
protected function generateRouteName()
{
return 'generated::'.Str::random();
} But I have no clue of how to change the generateRouteName() function to something deterministic like: protected function generateRouteName($url)
{
return 'generated::'.sha1($url);
} QuestionDoes anyone have an idea to how to make the route:cache deterministic, without naming all routes ? Kind regards, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thanks for this suggestion. I just named my unnamed routes "unnamed.1" to "unnamed.259". Yep there are 259 unnamed routes, because this project originates from Laravel 4.2 and was shifted to Laravel 7. After naming everything (don't forget See also #36448 |
Beta Was this translation helpful? Give feedback.
Thanks for this suggestion. I just named my unnamed routes "unnamed.1" to "unnamed.259". Yep there are 259 unnamed routes, because this project originates from Laravel 4.2 and was shifted to Laravel 7.
After naming everything (don't forget
api.php
and other files in theroutes
folder), thephp artisan route:cache
is finally determenistic.See also #36448