Home / Snippets / How to Clear Cache in Laravel
How to Clear Cache in Laravel cover

How to Clear Cache in Laravel

500

3 years ago

0 comments

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';
});
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this