Friday, October 24, 2025
HomeLanguagesLaravel Clear Cache Using Artisan Command and Programmatically

Laravel Clear Cache Using Artisan Command and Programmatically

In this laravel tutorial, you will learn how to clear cache from blade (views), routes, and config using the artisan command with the command line and programmatically without the command line in laravel apps.

When your app is in production mode and you need to implement caching in Laravel app or project to increase performance, it is important to note if you migrate the Laravel web application from development mode to production mode. so before that you have to clear the cache of your laravel web application

There are two methods to clear all types of caches such as root cache, view cache, app cache in laravel; the methods are the following:

Method 1: Clear Cache in Laravel using Artisan Command line

If you want to clear cache using commnad then open your terminal and go to the laravel application’s folder and execute below commands:

Clear Route Cache

To clear the route cache in Laravel using the PHP Artisan command-line interface, you can use the route:cache command.

php artisan route:cache

Clear Laravel Application Cache

You can clear laravel application cache by using the php artisan cache:clear command in Laravel:

php artisan cache:clear

Laravel Clear Config Cache

To clear the config cache in Laravel using the PHP Artisan command-line, you can use the config:cache command.

php artisan config:cache

Clear Laravel View Cache

To clear the cache in Laravel using the PHP Artisan command-line, you can use the view:clear command.

php artisan view:clear

Reoptimized Class

php artisan optimize

Method 2: Laravel Clear Cache Programmatically

If you want to clear the cache through browser then you need to execute these commands programmatically because sometimes hard to get console access to your laravel application. So this method is very easy and helpfull Clear Cache in Laravel using Browser.

Thus, you will create special routes to clear cache in Laravel.

 
//Clear route cache:
Route::get('/route-cache', function() {
$exitCode = Artisan::call('route:cache');
return 'Routes cache cleared';
});

//Clear config cache:
Route::get('/config-cache', function() {
$exitCode = Artisan::call('config:cache');
return 'Config cache cleared';
});

// Clear application cache:
Route::get('/clear-cache', function() {
$exitCode = Artisan::call('cache:clear');
return 'Application cache cleared';
});

// Clear view cache:
Route::get('/view-clear', function() {
$exitCode = Artisan::call('view:clear');
return 'View cache cleared';
});

If the cache is not cleared yet. Then go to bootstrap/cache directory. And delete all files and sub directories inside the bootstrap/cache directory.

Or, you can execute the following on the terminal instead of manually deleting the file:

cd bootstrap/cache/
rm -rf *.php

Recommended Laravel Tutorials

Recommended:-Laravel Try Catch

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS