Laravel 11 Clear Route,Config,View Cache

Laravel 11 clear cache using command line and artisan command example; Through this tutorial, i am going to show you two ways of how to clear all type of cache from laravel apps using command line and artisan command.

Laravel 11 Clear Route, Config and View Cache Methods

Here are two different ways to clear all types of cache from laravel application or project:

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 Tutorials

Leave a Comment