Laravel clear cache using the artisan command
In this tutorial, we will show How to use Laravel clear cache using the artisan command which can help you to clear your applications cache, route cache, views cache, and clear your config cache. Laravel cache is a hardware or software component that stores data so that future requests for that data can be served faster. Laravel cache is the result of an earlier computation or a copy of data stored elsewhere.
The clear config cache
config:cache
command is used to clear/delete the config file of your application.
php artisan config:cache Output: Configuration cache cleared! Configuration cached successfully!
Clear route-cache
route:cache
the command is used to clear route cache of your application.
php artisan route:cache Output: Route cache cleared! Routes cached successfully!
Clear view cache
view:clear
command is used to clear view cache of your application.
php artisan view:clear Output: Compiled views cleared!
Clear cache Laravel application
cache:clear
command is used to clear your application cache.
php artisan cache:clear
Output: Application cache cleared!
Above all commands are used only in your local command and the client is you can provide their server detail, but other clients do not provide server detail. So, we can also clear the cache by typing the code in the route file.
<?php #routes/web.php Route::get('/clear-caches', function() { $exitcode = Artisan::call('config:cache'); $exitcode = Artisan::call('view:clear'); $exitcode = Artisan::call('route:cache'); $exitcode = Artisan::call('cache:clear'); echo "Successfully cache clear!"; });
After adding the web.php file in the code we can clear all cache, view, route, and config in local environments as well as in the live server also worked. Now run this route you need to open your browser and add the URL.
http://localhost:8000/clear-caches
OR
https://your_domain/clear-caches