Home / Snippets / How to Clear Views Cache in Laravel
How to Clear Views Cache in Laravel cover

How to Clear Views Cache in Laravel

602

3 years ago

0 comments

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

notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this