phplaravellaravel-5command-line-interface

Laravel 5 – Clear Cache in Shared Hosting Server


The question is pretty clear.

php artisan cache:clear

Is there any workaround to clear the cache like the above command but without using CLI. I am using a popular shared hosting service, but as per my plan, I don't have control panel access.

I want to clear the views cache.

I saw a question almost the same like this, but it doesn't help me.


Solution

  • You can call an Artisan command outside the CLI.

    Route::get('/clear-cache', function() {
        $exitCode = Artisan::call('optimize:clear');
        // return what you want
    });
    

    You can check the official doc here http://laravel.com/docs/5.0/artisan#calling-commands-outside-of-cli

    Note the application cache is stored in the storage/framework/cache directory, but only if you configured the file driver in config/cache.php. You can choose many different drivers, such as Redis or Memcached, to improve performances over a file-based cache.