Ebook: List of important artisan commands in Laravel 6

Page 1


List of important artisan commands in Laravel Table of Contents ● ● ● ● ● ● ● ● ● ●

php artisan route:clear php artisan route:cache php artisan config:clear php artisan config:cache php artisan cache:clear php artisan view:clear php artisan view:cache php artisan optimize php artisan serve Conclusion

php artisan route:clear This command when fired, will clear your cached routes in web.php and api.php. Next time when laravel is booted it will automatically make a new cached file where routes are defined.

php artisan route:cache Use this command if you want to explicitly clear the cached routes and make new cached file with updated routes.

php artisan config:clear Laravel stores all the configuration from App/config directory to a single cached config file at App/bootstrap/cache/config.php​.

Whenever you add new config file or change existing config file in App/config directory, laravel will not take latest change by default rather we need to clear the cached config file, php artisan config:clear does the same thing for us.


php artisan config:cache This command clears the cached config file as mentioned above and recaches the latest configurations into a single file again.

php artisan cache:clear It will remove all the cache associated with the connection to the database.

php artisan view:clear In laravel blade files are compiled into normal php files and stored into cache at App/storage/framework/views directory

So if you have made any changes into blade files and they are not reflecting in browser, most probably latest changes might have not been cached hence run this command to clear the view caches.


php artisan view:cache This command serves the same purpose as above but additionally, it auto caches the latest view / blade file changes.

php artisan optimize Make use of this command extensively as this command will auto clear and recache all the configuration as well as blade files. Most of the time this command is used on production server after doing all the application configurations like creating database, composer install/update etc.

php artisan serve This is the most common artisan command we use. Why did I actually mentioned this here then ? Here is the reason. We need to make changes to​ ​.env file​ a lot while in development phase because we set variables in key = value pairs and these variables are accessed by configuration files. For example: App/config/app.php :

'name'​ => e ​ nv​(​'APP_NAME'​, ​'Laravel'​), .​env​ ​file​ : APP_NAME=AWESOME_APP

‘name’ variable first attempts to take value from the .env file where the key is APP_NAME and if there is no key as APP_NAME then it will take default values as Laravel. If we change APP_NAME value in .env file something like APP_NAME=MAGNIFICENT_APP, now ‘name’ variable will still be as AWESOME_APP until we stop the laravel application and re-run using php artisan serve

Conclusion In this article we discussed about various caching mechanisms laravel provides though artisan commands like route:clear, route:cache, config:clear, config:cache, view:clear etc. Original article at ​decodeweb.in


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.