Laravel Clear Cache, View, Routes and Config

Published on October 5, 2020 37 sec read

HIRE US 🖐
We're available to do freelance project. Take a look at our services!

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

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. 🙂

Author

Hey, I'm Md Obydullah. I build open-source projects and write on Laravel, Linux server, modern JavaScript and more on web development.

Follow

Leave a Reply

Your email address will not be published. Required fields are marked *