In this tutorial you will learn about the Laravel Clear Cache Using Artisan Command and its application with practical example.
Larave Clear Cache Using Artisan Command
In this laravel clear cache tutorial, I’ll show you various artisan commands to clear laravel cache of different types. You will also learn to clear cache on share hosting.
In Laravel, while developing a laravel application it is very often that changes we made are not reflecting. This is usually happens because of the laravel cache. Laravel provides various caching systems for developing fast loading laravel applications.
In this laravel clear cache example, we will learn to clear cache from command line (CLI), we will see how to clear cache from blade (views), routes,config etc using the command line and artisan command.
Useful Laravel Clear Cache commands
Here, we will discuss about various artisans commands used to clear different laravel cache in laravel applications.
Laravel Clear App Cache
To clear laravel application cache use the php artisan cache:clear artisan command as given below :
1 |
php artisan cache:clear |
Laravel Clear route cache
To clear route cache in laravel use the php artisan route:clear artisan command as given below :
1 |
php artisan route:clear |
Laravel Clear config cache
To clear config cache in laravel use the php artisan config:cache artisan command as given below :
1 |
php artisan config:cache |
Laravel Clear View Cache
To clear compiled view files cache in laravel use the php artisan view:clear artisan command as given below :
1 |
php artisan view:clear |
Laravel Reoptimized Class
Use the following laravel command to Reoptimized Class In laravel :
1 |
php artisan optimize |
Laravel Clear Cache On Shared Host
Most of the times in shared hosting servers we don’t have SSH access to the server. In that case, to clear laravel cache we have define routes in our application’s routes/web.php file that invoke the various laravel clear cache commands. This way we can clear Laravel cache by accessing specific routes in the browser.
Laravel Clear Route Cache from Browser
1 2 3 4 |
Route::get('/route-cache', function() { $exitCode = Artisan::call('route:cache'); return 'Routes cache cleared'; }); |
Laravel Clear Config Cache from Browser
1 2 3 4 |
Route::get('/config-cache', function() { $exitCode = Artisan::call('config:cache'); return 'Config cache cleared'; }); |
Laravel Clear Application Cache from Browser
1 2 3 4 |
Route::get('/clear-cache', function() { $exitCode = Artisan::call('cache:clear'); return 'Application cache cleared'; }); |
Laravel Clear View Cache from Browser
1 2 3 4 |
Route::get('/view-clear', function() { $exitCode = Artisan::call('view:clear'); return 'View cache cleared'; }); |