Laravel 9 Clear Cache of Application Route, View & Config

Reading Time: 5 minutes
2,868 Views

When we do application development in Laravel, as a developer you may have observed that site saves cache of route, view and routes. Due to this, sometime changes doesn’t reflect to pages, we get the old data on the output screen.

To overcome this issue we are going to see the concept of Laravel 9 Clear cache of application route, view & config.

The commands we will see not actually dependent on laravel version. It runs to all application of any version. These are global artisan commands. It provides the list of artisan command which helps to remove complete caches.

Inside this tutorial we will see Clear cache of route, view and configuration of laravel application.

Learn More –

Let’s get started.

Laravel Installation

Open terminal and run this command to create a laravel project.

composer create-project laravel/laravel myblog

It will create a project folder with name myblog inside your local system.

To start the development server of laravel –

php artisan serve

URL: http://127.0.0.1:8000

Assuming laravel already installed inside your system.

Laravel Artisan Command Panel

When we open laravel project into terminal and type the command

$ php artisan

You will see these commands.

This is complete commands list of laravel artisan. Inside this list you see the caches command to clear routes, views, optimized files, etc.

Cache Related Commands

Here,

We have listed all the artisan commands which will perform to clear caches of routes, views, etc.

Clear Application Compiled Classes

Remove the compiled class files

$ php artisan clear-compiled

Clear Application Cache

Flush the application cache

$ php artisan cache:clear

Clear Route Cache

Remove the route cache file

$ php artisan route:clear

Clear View Cache

Clear all compiled view files

$ php artisan view:clear

Clear Config Cache

Remove the configuration cache file

$ php artisan config:clear

Clear Application Scheduler Cache

Delete the cached mutex files created by scheduler

$ php artisan schedule:clear-cache

Clear All Queue Jobs

Delete all of the jobs from the specified queue

$ php artisan queue:clear

Remove All Event Cached Files

Clear all cached events and listeners

$ php artisan event:clear

Remove All Cached Bootstrap Files (Master Command)

Remove the cached bootstrap files. This command will do all caches clear of your application.

$ php artisan optimize:clear

Output

Cached events cleared successfully.
Compiled views cleared successfully.
Application cache cleared successfully.
Route cache cleared successfully.
Configuration cache cleared successfully.
Compiled services and packages files removed successfully.
Caches cleared successfully.

Execute Cache Command by Code

Inside this we will create a route inside web.php of /routes folder. That route when we call, then it clears the cache of the application.

//...

use Illuminate\Support\Facades\Artisan;

Route::get('clear-all-cache', function() {
  
    Artisan::call('cache:clear');
    dd("Successfully, you have cleared all cache of application.");
});


//...

Behind the scene, it is going to execute the command as

$ php artisan cache:clear

Same we can do for route [ Artisan::call(‘route:clear’); ], views [ Artisan::call(‘view:clear’); ] & config [ Artisan::call(‘config:clear’); ]

Application Testing

Run this command into project terminal to start development server,

php artisan serve

URL- http://localhost:8000/clear-all-cache

We hope this article helped you to learn about Laravel 9 Clear Cache of Application Route, View & Config Tutorial in a very detailed way.

Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.