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
Leave a reply