How to clear cache in Laravel?

Stefan Izdrail

Founder & Senior Architect · 2026-06-29

Laravel Company
Title: Effectively Clearing Cache in Laravel for Seamless Updates Introduction Clearing cache is an essential part of web development, especially when you need to make changes to your code and ensure they are reflected on the front-end. In this comprehensive blog post, we will discuss how to clear cache effectively in Laravel, ensuring that your website operates at its optimum potential. Why Clear Cache? Websites utilize multiple layers of caching to speed up their performance. Some examples include browser cache, server cache, and application cache. When you make changes in your code, particularly CSS or JavaScript files, it is vital to clear these caches so that the latest modifications are reflected on your website. Failure to do so can lead to inconsistencies between your local development environment and live site. Clearing Cache Manually To begin, let's discuss clearing cache manually by using Laravel's built-in Artisan commands. In your terminal window, navigate to the root directory of your Laravel project and execute the following command: ```bash php artisan cache:clear ``` This command will clear all application cache, including configuration files, route caches, view caches, and any other related caches. Clearing Cache Automatically (Using Laravel Mix) If you are using Laravel Mix to manage your assets like CSS and JavaScript files, you may already be familiar with the `mix()` helper function. This helper function automatically generates a unique hash for each file, which can cause issues when making changes to these files. To overcome this and ensure that the latest changes are reflected on your website, follow these steps: 1. In your terminal window, navigate to the root directory of your Laravel project and run the command `npm install`. This will install all dependencies necessary for building assets using Laravel Mix. 2. In your project's `webpack.mix.js` file, locate the lines where you register and mix CSS files: ```javascript mix.js('resources/js/app.js', 'public/js') .sass('resources/sass/app.scss', 'public/css') ``` Replace them with the following code snippet, including a force option to erase existing assets: ```javascript mix.js('resources/js/app.js', 'public/js') .options({ processCssUrls: false, publicPath: '/test' }) .sass('resources/sass/app.scss', 'public/css') ``` Alternatively, you could use the `mix()` helper function as follows: ```javascript mix.js('resources/js/app.js', 'public/js') .options({ processCssUrls: false, publicPath: '/test' }) .sass('resources/sass/app.scss', 'public/css') .mix() ``` This ensures that the path to your CSS file will be generated without any hash and you can make changes directly in this file, and they will reflect on the front end when building assets again. Conclusion Clearing cache is an essential step in maintaining a smooth development process. By employing Laravel's built-in Artisan commands or using Laravel Mix for managing assets, you can ensure that your code modifications are reflected accurately on your website. Don't forget to check out https://laravelcompany.com/blog for more helpful tips and tricks related to Laravel development!