Laravel 5 how to clear cache using composer.json

2019-03-06 09:23发布

问题:

I am new to Laravel. I am trying to clear view cache, and I need to clear view cache without composer.

Is possible to clear cache using composer.json autoload?

I have already tried the code below, but it was not working.

routes.php

Route::get('/view-clear', function() {
    $exitCode = Artisan::call('view:clear');
    return '<h1>View cache cleared</h1>';
});

Also, how should I use...

Cache::flush();

...in my code controller.

回答1:

With a Filemanager or a Simple PHP Code Delete the compiled views inside of storage\framework\views

Example:

Route::get('/view-clear', function() {
    $directory=storage_path('framework/views');  
    $files=File::allFiles($directory);
    File::delete($files);
    return '<h1>View cache cleared</h1>';
});


回答2:

May be something like this?

public function index()
    {
        $value = Cache::flush();

        return view('your.view')->with($value);
    }


回答3:

Why not try clear browser cache ?

I think the view cache saved by browser.