Posts Learn Components Snippets Categories Tags Tools About
/

How to Clear Cache in Laravel

Learn how to clear cache in Laravel 6/7/8 and get your route, views, configuration cleaned

Created on Jul 21, 2021

483 views

In this snippet, you'll learn how to clear Laravel Application Cache, Laravel Config Cache, Laravel Route Cache, and Laravel Compiled Views Cache.

Clear Application Cache


To clear your Laravel application cache you can run the command below.
php artisan cache:clear

Clear Configuration Cache


To clean your environment (.env) configuration cache, run the command below.
php artisan config:clear

Clear Route Cache


To clear all of your Laravel route cache you can run the command below.
php artisan route:clear

Clear Compiled Views Cache


To clear the compiled views cache that Laravel has rendered, you can run the command below.
php artisan view:clear

Extra: Clear Cache from Browser


Sometimes you might have no access (SSH) to the terminal in production. In this case, you can define a new web route to clear the cache.
# /routes/web.php

<?php

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

  return 'The application cache has been cleared';
});

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for How to Clear Cache in Laravel

)