Hello friends, long time no see ? hehe, I really apologize for the late post after my last article on multi guard authentication. I was quite busy on multiple projects at work. As we all know Taylor Otwell has released a major version of his masterpiece, Laravel 6 recently. Quite impressive, but even though Laravel has moved to version 6 most of the developers are still confused about some of the artisan commands which are the core of Laravel CLI operations.

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’ => env(‘APP_NAME’, ‘Laravel’),

.env file :

‘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


In this article we discussed about various caching mechanisms laravel provides though artisan commands like php artisan route:clear, php artisan route:cache, php artisan config:clear, php artisan config:cache, php artisan view:clear etc.

#web-development #laravel

List of the artisan commands, developers are still confused even after release of laravel 6 » Decode Web
8.90 GEEK