php artisan optimize will do the following tasks:
It clears the config cache, and re-cache it again. It also will clear route cache. and then re-cache routes and also files.
Before you continue with the rest of this tutorial, I would like to introduce two packages for Laravel that I have recently developed: Laravel Pay Pocket, a modern multi-wallet package, and Laravel Failed Jobs, a UI for the Laravel Failed Jobs Table. I hope they may be of help to you.
https://github.com/HPWebdeveloper/laravel-pay-pocket
https://github.com/HPWebdeveloper/laravel-failed-jobs
If you already did
php artisan route:cache
And want to clear cached routes, you need only to do:
php artisan route:clear
For config file you can do
php artisan config:clear
For view files you can do
php artisan view:clear
Alternative:
This directory is the place of all cached file in any Laravel project.
bootstrap/cache/
Removing this file will remove the routes cache on your server :
bootstrap/cache/routes.php
Another alternative:
You can assign clearing the cache file to a controller or running it internally.
You need only to put the following line in an action in a controller and call that method in one of your routes:
\Artisan::call('route:clear');
Optimizing Route Loading is a must on production :
The pros are pretty clear. After caching, your site gets faster.
If you are building a large application with many routes, you should make sure that you are running the route:cache Artisan command during your deployment process which will update the cached file.
You can run this command on the server:
php artisan route:cache
Or if you run the above command in your local you only need to upload this file bootstrap/cache/routes.php
to your server.
Caching routes reduces all of your route registrations into a single method call within a cached file for improving the performance of route registration when registering hundreds of routes.
The cons of caching route are that once you cache the site’s routes, you have to re-cache your routes every time you make any changes to routes.php
, or the changes won't show up.