How to Clear Cache in Laravel 8/7/6

Laravel 8,7,6,5 clear cache using command line and artisan command example; In this laravel tutorial, i will show you two methods of how to clear all type of cache from laravel apps using command line and artisan command.

Caching is the act of transparently storing data for future use in an attempt to make applications run faster. There are all kinds of ways to cache data, and Laravel makes it easy to do so with just a small number of method calls.

Laravel 8/7/6 Clear Route, Config and View Cache Methods

  • Laravel 8/7/6 Cache Clear using Command Line
  • Laravel 8/7/6 Cache Clear using Artisan Command

1 – Laravel Cache Clear using Command Line

Laravel clear all cache using command line:

  • Laravel Clear Route Cache
  • Laravel Clear App Cache
  • Laravel Clear Config Cache
  • Laravel Clear View Cache
  • Laravel Clear Cache using Reoptimized Class

Laravel Clear Route Cache

Use the below command and clear your routes cache :

php artisan route:cache

Laravel Clear App Cache

Use the below command and clear your application cache like session cache, cookies cache:

php artisan cache:clear

Laravel Clear Config Cache

Use the below command and clear your config cache :

php artisan config:cache

Laravel Clear View Cache

Use the below command and clear your view (blade) cache :

php artisan view:clear

Laravel Clear Cache using Reoptimized Class

php artisan optimize

2 – Laravel Cache Clear using Artisan Command

If you do not access SSH on shared hosting servers, then we can also clear the cache by typing the code in route file. Go to your web.php file and put below code for clear cache of your application :

 
//Clear route cache:
Route::get('/route-cache', function() {
$exitCode = Artisan::call('route:cache');
return 'Routes cache cleared';
});

//Clear config cache:
Route::get('/config-cache', function() {
$exitCode = Artisan::call('config:cache');
return 'Config cache cleared';
});

// Clear application cache:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('cache:clear');
return 'Application cache cleared';
});

// Clear view cache:
Route::get('/view-clear', function() {
$exitCode = Artisan::call('view:clear');
return 'View cache cleared';
});

Recommended Laravel Posts

Leave a Comment