How to Clear Cache in Laravel 11 using Artisan Command?

28-Mar-2024

.

Admin

How to Clear Cache in Laravel 11 using Artisan Command?

Hello Dev,

In this brief guide, I'll illustrate the process of clearing cache for routes, views, configurations, and events in a Laravel 11 application.

There are instances where we find it necessary to clear the cache, especially after modifying configuration or view files over an extended period. In such cases, the following command proves invaluable for cache clearance in Laravel 11:

Allow me to share my own encounter and its resolution. While developing my Laravel e-commerce platform hosted on GitLab, I encountered a frustrating issue wherein my view cache persisted with errors despite multiple attempts to refresh it. After exhausting various approaches, I found solace in Laravel's command-line utilities. Consequently, I've compiled a series of commands aimed at efficiently clearing cache across views, routes, configurations, and more. Let's delve into the specifics:

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

laravel-11-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

laravel-11-route-clear-2

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

laravel-11-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

laravel-11-config-clear-2

5) Event Cache Clear in Laravel 11

This command will help to clear cache of events.

Clear Event Cache:

php artisan event:clear

laravel-11-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

laravel-11-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...

#Laravel 11