To clear the cache programmatically and artisan commands in Laravel applications Use a facade of cache to clear all types of caches programmatically, and you can also use different php artisan
commands to clear the cache of routes, config, app, and views.
Option 1: Clear Cache Programmatically in Laravel
Simply use laravel cache facade to remove or clear all types of caches like config, route, views, etc from laravel applications.
Here is the code to programmatically clear Laravel’s cache:
use Illuminate\Support\Facades\Cache; Cache::flush();
Option 2: Clear Cache using Artisan Command in Laravel
You can clear or delete the cache of configurations, routes, views, etc. from Laravel projects using the command line interface, as you will find some commands using which you can clear any type of cache from Laravel’s apps.
Run php artisan route:cache
command on cmd or command line to clear the route cache in Laravel:
php artisan route:cache
Run php artisan cache:clear
command on cmd or command line to clear the application cache in Laravel:
php artisan cache:clear
To clear the config cache in Laravel, run php artisan config:cache
command on cmd or command line:
php artisan config:cache
To clear the view cache in Laravel, run php artisan view:clear
command on cmd or command line:
php artisan view:clear
Conclusion
That’s it; you have learned how to clear programmatically and using artisan command to clear all types of cache from laravel applications.
Thanks for this clear cache in laravel post, I have to clear the cache on shared using this article.
All the commands for clear cache in laravel ars very useful for me.
laravel clear cache shared hosting
laravel clear cache config
laravel clear cache command line
laravel clear cache without artisan
Thanks
All in one
Terminal:
php artisan optimize:clear
Application :
Route::get(‘/clear-cache’, function() {
Artisan::call(‘optimize:clear’);
echo Artisan::output();
});