How to Clear Cache in Laravel 9 using Artisan Commands?

Feb 22, 2022 . Admin

Hi friends,

In this example of how to clear cache in laravel 9 using artisan commands?. This example will give you a simple example of laravel 9 cache clear config using artisan command. i explain simply clear cache from the artisan command line (cli) in laravel 9.

In this tutorial i am giving information about laravel 9 artisan command which can help you to clear you application's cache , route cache , clear your application's view , and clear Your config cache as well as. The application cache is the primary cache in laravel 9. In this tutorial, we are going to learn how to clear all cache one command with artisan command-line interface.

So let's start following example:

1) Application Cache Clear in Laravel 9

2) Route Cache Clear in Laravel 9

3) View Cache Clear in Laravel 9

4) Config Cache Clear in Laravel 9

5) Event Cache Clear in Laravel 9

6) All Cache Clear in Laravel 9

7) Cache Clear by Route in Laravel 9

Step 1: Download Laravel

Let us begin the tutorial by installing a new laravel application. if you have already created the project, then skip following step.

composer create-project laravel/laravel example-app
2 : Application Cache Clear in Laravel 9

This command will clean all application cache clear

Clear Cache:
php artisan cache:clear
3 : Route Cache Clear in Laravel 9

This command will help to clear cache of routes.

Clear Route Cache:
php artisan route:clear
4 : View Cache Clear in Laravel 9

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

Clear View Cache:
php artisan view:clear
5 : Config Cache Clear in Laravel 9

This command will help to clear cache of config.

Clear Config Cache:
php artisan config:clear
6 : Event Cache Clear in Laravel 9

This command will help to clear cache of events.

Clear Event Cache:
php artisan event:clear
7 : All Cache Clear in Laravel 9

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

Command:
php artisan optimize:clear
8 : Cache Clear by Route in Laravel 9

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 9