Laravel 11 Clear Cache of Route, View, Config, Event Commands

By Hardik Savani September 4, 2024 Category : Laravel

In this short article, I will show you how to clear cache of routes, views, config, and events in a Laravel 11 application.

Sometimes we need to clear the cache when changes are made in a configuration file or in the view file after a long time. So, the below command will help you to clear cache in Laravel 11.

I want to share my experience and solution. When I was working on my Laravel e-commerce website with GitLab, I encountered an issue where my view cache showed an error during development. I tried various methods to refresh it, but I couldn't see any changes in my view. Eventually, I resolved my problem using Laravel commands. So, let's see, I've added several commands to clear the cache from views, routes, configurations, etc.

Step for How to Cache Clear of Routes, Views, Config and Events in Laravel 11?

  • 1) Application Cache Clear in Laravel 11
  • 2) Route Cache Clear in Laravel 11
  • 3) View Cache Clear in Laravel 11
  • 4) Config Cache Clear in Laravel 11
  • 5) Event Cache Clear in Laravel 11
  • 6) All Cache Clear in Laravel 11
  • 7) Cache Clear by Route in Laravel 11

1) Application Cache Clear in Laravel 11

This command will clean all application cache clear

Clear Cache:

php artisan cache:clear

2) Route Cache Clear in Laravel 11

This command will help to clear cache of routes.

Clear Route Cache:

php artisan route:clear

3) View Cache Clear in Laravel 11

This command will help to clear cache of views/blade files.

Clear View Cache:

php artisan view:clear

4) Config Cache Clear in Laravel 11

This command will help to clear cache of config.

Clear Config Cache:

php artisan config:clear

5) Event Cache Clear in Laravel 11

This command will help to clear cache of events.

Clear Event Cache:

php artisan event:clear

6) All Cache Clear in Laravel 11

This command will help to clear cache of config, views, cache files etc.

Command:

php artisan optimize:clear

7) Cache Clear by Route in Laravel 11

You can also clear cache without command using route. so you can create route as like bellow:

Route::get('/clear-cache-all', function() {

    Artisan::call('cache:clear');
  
    dd("Cache Clear All");
});

I hope it can help you...

Shares