Clear Cache in Laravel Using Laravel Artisan Command

In this tutorial I am giving information about the laravel artisan command which can help you to clear your application’s cache, route cache, clear your application’s view, and clear Your config cache as well.

We can run these all commands in the command-line interface (CLI) as well as we can create one function which has stored all these functions and run direct this function without open your terminal. So, let’s start. Clear Config Cache 

This command is used to clear/delete the config bootstrap/cache/config.php file of your application.

php artisan config:cache

Clear Route Cache

This command is used to clear the route cache of your application.

php artisan route:cache

Clear Cache Laravel Application

This command is used to clear your application cache :

php artisan cache:clear

Clear View Cache Laravel

 This command is used to clear the view of the cache of your application.

php artisan view:clear

Above all commands are used only in your local command window, As we don’t have access to SSL on shared hosting servers. So, we can also clear the cache by typing the code in the route file. Go to your routes/web.php file and put the below code.


Route::get('/clear-cache', function() {
	 $exitCode = Artisan::call('config:cache');
     $exitCode = Artisan::call('cache:clear');
     $exitCode = Artisan::call('view:clear');
     $exitCode = Artisan::call('route:cache');

After adding the above code we can clear all cache, view, route, config in local environments as well as in the live server also.

To run this route you need to open your browser and after add this route like below.

http://localhost:8000/clear-cache OR http://your_site_name/clear-cache

You May Also Like

About the Author: Sumanta Kabiraj

Leave a Reply

Your email address will not be published.