Laravel Clear Cache, View, Routes and Config

Sometimes after route, creating view page or after installing new package, some features don’t work properly. Caching is responsible for these types of issues. Let’s have a look how to clear cache, view, routes and config.

Table of Contents

  1. Using CLI
  2. Using Artisan Command

Using CLI

Just run these commands on CLI. Clear Cache:

php artisan cache:clear

Clear View:

php artisan view:clear

Clear Routes:

php artisan route:cache

Clear Config:

php artisan config:cache

Clear Session Files:

rm -f storage/framework/sessions/*

Reoptimized Class:

php artisan optimize

Using Artisan Command

Open routes/web.php and paste these lines:

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

 // 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 view cache
Route::get('/view-clear', function() {
    $exitCode = Artisan::call('view:clear');
    return 'View cache cleared';
});

On shared hosting, you can clear eveything using this way.

The tutorial is over. Thanks for reading. ?