To clear all types of cache such as route, config, view, and app in laravel, Just open your command line or CMD and use the PHP Artisan command to clear cache from your Laravel application or project.
In Laravel project you can clear all types of cache by running the artisan command on cmd or command line and without using the artisan command.
How to Clear Cache from Laravel 11|10|9
Here are two options to clear route, app, config, and view cache in Laravel 11|10|9 project using artisan command on command lline or cmd:
Option 1 – Laravel Clear route, app, config, view cache using Command Line
Here are PHP artisan commands to delete or clear route, app, config, and view caches using artisan commands:
Laravel Clear Route Cache
Use the below command and clear your routes cache :
php artisan route:cache
Laravel Clear App Cache
Use the below command and clear your application cache like session cache, cookies cache:
php artisan cache:clear
Laravel Clear Config Cache
Use the below command and clear your config cache :
php artisan config:cache
Laravel Clear View Cache
Use the below command and clear your view (blade) cache :
php artisan view:clear
Laravel Clear Cache using Reoptimized Class
php artisan optimize
Solution 2 – Laravel Cache Clear using without Command
If you are unable to access SSH on shared hosting servers, there is an alternative method to clear the cache by modifying the route file. To do this, follow the steps below:
- Locate the
web.php
file in your project. This file is usually located in theroutes
directory. - Open the
web.php
file in a text editor or an integrated development environment (IDE). - Insert the following code snippet at the desired location within the file:
//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';
});
Then save the changes to the web.php
file.
Now, you can clear the cache of your application by accessing the /clear-cache
URL in your web browser. For example, if your website URL is http://example.com
, you would visit http://example.com/clear-cache
.
After accessing the URL, the cache of your application will be cleared, and you should see a message indicating successful cache clearance.
If the cache is not cleared yet. Then go to the 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