Clear caching in Laravel

Laravel clear cache

To clear caching in Laravel, you can use Artisan commands to remove various cached data types. We can clear cache using command line with Laravel artisan commands. Run following command in command line one by one.

1. Clear Application Cache:

Removes cached application settings (e.g., config, routes):

php artisan cache:clear

 2. Clear Config Cache:

Removes the compiled configuration file (config.php):

php artisan config:clear

3. Clear Route Cache:

Clears the cached route definitions:

php artisan route:clear

4. Clear View Cache:

Removes compiled Blade view files:

php artisan view:clear

5. Clear Event Cache:

Deletes cached event and listener mappings:

php artisan event:clear

6. Rebuild Caches:

Rebuild caches after clearing:


php artisan config:cache
php artisan route:cache

 

Now we can clear all cache on server without using command line

Route::get('/clear', function() {

   Artisan::call('cache:clear');
   Artisan::call('clear-compiled');
   Artisan::call('config:clear');
   Artisan::call('config:cache');
   Artisan::call('view:clear');

   return "Cleared!";

});

Leave a Reply

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


Follow by Email
YouTube
YouTube
LinkedIn
Share
Instagram