Many times you face an issue that any changes to the Laravel application are not reflecting on web interfaces. This occurred due to the application is being served by the cache. This tutorial will help you to clear the cache in the Laravel application.
Clear Cache in Laravel (Terminal)
Log in to the system running your Laravel application and open a terminal. Then navigate to your Laravel application code. Here you can issue the commands to clear cache as followings:
Clear Application Cache
Run the following command to clear the application cache of the Laravel application.
php artisan cache:clear
Clear Route Cache
To clear route cache of your Laravel application execute the following command from the shell.
php artisan route:clear
Clear Configuration Cache
You can use config:clear to clear the config cache of the Laravel application.
php artisan config:clear
Clear Compiled Views Cache
Also, you may need to clear compiled view files of your Laravel application. To clear compiled view files run the following command from the terminal.
php artisan view:clear
Clear Cache in Laravel (Browser)
Most of the shared hosting providers don’t provide SSH access to the systems. In that case, you can clear the Laravel cache by calling the URL in the browser. You can simply place the below code in your routes/web.php
file of the Laravel application. Then access this URL in the browser to clear the cache of the Laravel application.
1 2 3 4 | Route::get('/clear-cache', function() { Artisan::call('cache:clear'); return "Cache is cleared"; }); |
Thanks you 🙂 Be safe
Thanks a lot. It’s very useful for me.
The question is pretty clear.
php artisan cache:clear
Is there any workaround to clear the cache like above we using in CLI. I am using a popular shared hosting service, but as per my plan, I don’t have control panel access.
** I want to clear the views cache.**
All in one
Route::get(‘/clear-cache’, function() {
Artisan::call(‘optimize:clear’);
echo Artisan::output();
});
Thank you very much. It helps me a lot as a beginner in laravel.
Thanks buddy. Are you a Laravel developer?
Please change clear route cache from ‘php artisan route:cache ‘ to ‘php artisan route:clear’.
Thanks,
Anu
Thanks Anupama, I have corrected the command.
Thanks useful
i readed your infomation and I am very impressed for you. Thanks you for your sharing. It is very useful !
I have the same problem.
Calling / clear-cache is enough for all clients to see the same page, or do we have to make the call on each client computer?
Please fix this error in your post:
php artisan config:cache does not clear your cache. This will cause problems with unit tests.
It should be php artisan config:clear
thankss for sharing
In the browser:
instead of Artisan simply use
cache()->clear();
IMPORTANT! #3 should be:
php artisan config:clear
NOT config:cache
Hey, Rahul, would you mind updating the article? I spent a bunch of time debugging a problem with env() after running config:cache. Your article has a high Google result for “laravel clear cache” and it would be nice for the information to be correct.
php artisan route:cache ?? clear
I ran the commands and the laravel site stop working: appear 404
Not Found. Any help will be appreciate.
Thanks
php artisan route:cache is to cache the route
Run
php artisan route:clear
php artisan config:clear
Laravel provides an expressive, unified API for various caching backends. Also, Laravel is configured to use the file cache driver, which stores the serialized, cached objects in the filesystem. I would like to add that the above-listed steps to clear cache are easy to follow and important too for Laravel Application Development.