Home > Back-end >  Why i need to run php artisan optimize after adding a route
Why i need to run php artisan optimize after adding a route

Time:03-13

if I don't run this command, and I go to this route in browser => Page not found

CodePudding user response:

Run

Php artisan route:clear

It will clear the cache

CodePudding user response:

When you do

php artisan route:cache

A file like bootstrap\cache\routes-v7.php gets created holding all your routes from routes\*.php which are contained in Route methods that weight some calculation cost on your server each time you send a request to figure what to do for the current route.

Quoting from bootstrap\cache\routes-v7.php comments:

This allows us to instantaneously load the entire route map into the router.

Important:

  • This cache file doesn't get auto updates and doesn't exist in a fresh project.
  • This cache takes precedence over routes\*.php files.
  • The bootstrap\cache folder is ignored by default by git.

So everytime you push a new version of your project to production you need to run php artisan route:cache.

On dev environment it is better to have no cache and ensure that by running php artisan route:clear.

Here is an extensive great article for more details https://voltagead.com/laravel-route-caching-for-improved-performance/

Note that the optimize command was removed from the framework then added back.

  • Related