Laravel 10 Clear Cache with Artisan Command
Laravel Clear Cache with Artisan Command
Laravel Clear Cache with Artisan Command tutorial, we’ll cover how to clear various caches in a Laravel application using the artisan command-line interface. Specifically, we’ll learn to clear route cache, Laravel application cache, config cache, view cache, and re-optimize classes. Additionally, we’ll explore alternative methods for removing cache in Laravel without relying on artisan commands.
I’m certain that many of you have encountered situations where changes made in the app are not reflected in the view.
This issue arises due to Laravel’s robust caching mechanism, which serves cached data.
If you’re still experiencing this problem, there’s no need to fret. Allow me to introduce you to some of the top artisan commands for clearing the cache in your Laravel application via the PHP artisan command-line interface.
1. Clear Route Cache in Laravel
Laravel caching system also takes routes in consideration, to remove route cache in Laravel use the given below command:
php artisan route:cache
2. Clear Application Cache in Laravel
Run the following command to clear application cache:
php artisan cache:clear
3. Clear Config Cache in Laravel
Run the following command to clear config cache
php artisan config:cache
4. Clear View Cache in Laravel
Run the following command to clean your view cache:
php artisan view:clear
5. Laravel clear cache without artisan
It’s not feasible to access SSH on shared hosting servers for utilizing artisan commands to clear, remove, or delete cache in Laravel. However, there’s another workaround in my repertoire, which involves incorporating the Artisan::call() method within the routes/web.php file using the methods provided below. As you can observe, it’s incredibly straightforward.
As you can see, how much simple is that:
// Remove route cache
Route::get('/clear-route-cache', function() {
$exitCode = Artisan::call('route:cache');
return 'All routes cache has just been removed';
});
//Remove config cache
Route::get('/clear-config-cache', function() {
$exitCode = Artisan::call('config:cache');
return 'Config cache has just been removed';
});
// Remove application cache
Route::get('/clear-app-cache', function() {
$exitCode = Artisan::call('cache:clear');
return 'Application cache has just been removed';
});
// Remove view cache
Route::get('/clear-view-cache', function() {
$exitCode = Artisan::call('view:clear');
return 'View cache has jut been removed';
});
Its your turn to let me know what do you think about this laravel clear cache tutorial.
Thanks for reading