Posts Learn Components Snippets Categories Tags Tools About
/

How to Clear Views Cache in Laravel

Learn how to clear views cache in Laravel using the artisan command as well as programatically the easy way

Created on Oct 26, 2021

576 views

There are several caches in Laravel and to clear the views cache you can make use of the artisan command as well as programmatically call it from the code itself. The views cache in Laravel stores the compiled views that are original "blade" files to the traditional "php" file which then is readable to PHP engine. If you do curious about the compiled files then you can visit them within the "storage" directory.
storage/framework/views

Clear Compiled Views Cache in Laravel


To clear the compiled views cache that Laravel has rendered, you can run the view clear artisan command below.
php artisan view:clear
Do note that the command will clear all the compiled template (all files within the storage/framework/views) directory.

Clear Views Cache Programmatically from Code


To clear the views cache programmatically from the backend, you can make use of the Artisan facade.
<?php # /routes/web.php

Route::get('/clear-views-cache', function () {
    Artisan::call('view:clear');
});
This is very useful when you want to set a scheduler such as during midnight or after some pages have been updated and you want to explicitly clear the views.

Other Reads

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for How to Clear Views Cache in Laravel

)