Laravel 5 Clear Views Cache

PhpCachingLaravelLaravel 5Laravel Artisan

Php Problem Overview


I notice that Laravel cache views are stored in ~/storage/framework/views. Over time, they get to eat up my space. How do I delete them? Is there any command that could? I tried php artisan cache:clear, but it is not clearing the views cache. With that, I have to manually delete the files in the said folder.

Also, how do I disable the views caching?

Php Solutions


Solution 1 - Php

There is now a php artisan view:clear command for this task since Laravel 5.1

Solution 2 - Php

To get all the artisan command, type...

php artisan

If you want to clear view cache, just use:

php artisan view:clear

If you don't know how to use specific artisan command, just add "help" (see below)

php artisan help view:clear

Solution 3 - Php

please try this below command :

sudo php artisan cache:clear

sudo php artisan view:clear

sudo php artisan config:cache

Solution 4 - Php

in Ubuntu system try to run below command:

sudo php artisan cache:clear

sudo php artisan view:clear

sudo php artisan config:cache

Solution 5 - Php

To answer your additional question how disable views caching:

You can do this by automatically delete the files in the folder for each request with the command php artisan view:clear mentioned by DilipGurung. Here is an example Middleware class from https://stackoverflow.com/a/38598434/2311074

<?php
namespace App\Http\Middleware;

use Artisan;
use Closure;

class ClearViewCache
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (env('APP_DEBUG') || env('APP_ENV') === 'local') 
            Artisan::call('view:clear');

        return $next($request);
    }
}

However you may note that Larevel will recompile the files in the /app/storage/views folder whenever the time on the views files is earlier than the time on the PHP blade files for the layout. THus, I cannot really think of a scenario where this would be necessary to do.

Solution 6 - Php

Right now there is no view:clear command. For laravel 4 this can probably help you: https://gist.github.com/cjonstrup/8228165

Disabling caching can be done by skipping blade. View caching is done because blade compiling each time is a waste of time.

Solution 7 - Php

use Below command in terminal

php artisan cache:clear
php artisan route:cache 
php artisan config:cache 
php artisan view:clear

Solution 8 - Php

Here is a helper that I wrote to solve this issue for my projects. It makes it super simple and easy to be able to clear everything out quickly and with a single command.

https://github.com/Traqza/clear-everything

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionbasagabiView Question on Stackoverflow
Solution 1 - PhpDilipGurungView Answer on Stackoverflow
Solution 2 - PhpJake PucanView Answer on Stackoverflow
Solution 3 - PhpMosam PrajapatiView Answer on Stackoverflow
Solution 4 - PhpMosam PrajapatiView Answer on Stackoverflow
Solution 5 - PhpAdamView Answer on Stackoverflow
Solution 6 - PhpArjanSchoutenView Answer on Stackoverflow
Solution 7 - PhpUddyan SemwalView Answer on Stackoverflow
Solution 8 - PhpkrayView Answer on Stackoverflow