Caching is an essential feature of web applications, including Laravel. Laravel provides a simple way to clear various caches, such as route cache, view cache, configuration cache, etc. Here are some ways on How to Clear Cache in Laravel using Artisan Command.
1. Clear Application Cache
To clear the application cache, you can use the cache:clear Artisan command. Open your terminal or command prompt and run the following command in your Laravel project’s root directory:
php artisan cache:clear
2. Clear Configuration Cache
If you have made changes to your application’s configuration files (e.g.,
config/app.php), you’ll need to clear the configuration cache. Use the
config:clear Artisan command:
php artisan config:cache
3. Clear Route Cache
Laravel allows you to cache your application’s routes to optimize the routing process. If you have made changes to your routes, you can clear the route cache using the
route:clear Artisan command:
php artisan route:clear
4. Clear View Cache
If you are using Laravel’s view caching feature, you might need to clear the view cache after making changes to your views. Use the
view:clear Artisan command:
php artisan view:clear
5. Clear the optimized class loader cache
Laravel uses a class loader to load classes quickly. The class loader generates a cache file to speed up the class-loading process. To clear the optimized class loader cache, use the following command:
php artisan optimize:clear
6. Clearing Composer Cache
Sometimes, a new package you just installed via Composer doesn’t appear to be working at all. Or a new project you just cloned from a repository doesn’t seem to be running correctly.
In such a situation, you need to update the PHP autoloader by running the following command:
7. Clearing NPM Cache
To clear NPM cache:
npm cache clean --force
Remember to run these commands with appropriate permissions and ensure that you are in your Laravel project’s root directory when executing the Artisan commands.
By using these cache clearing methods, you can keep your Laravel application up to date and avoid any inconsistencies caused by cached data.