How to clear cache in laravel without using command line/terminal?

November 12, 2021
Laravel
How to clear cache in laravel without using command line/terminal?


In this tutorial, I am going to show you that how you can clear the cache in Laravel without writing artisan command.

Sounds like you cannot have access to the terminal/ssh and want to clear the cache without using the command prompt or terminal? Or you are looking for how to clear Laravel cache in Cpanel?

Don’t worry I got you covered 🙂 Let’s get started!!!

Thanks to Laravel, if you cannot use the artisan commands via terminal, you can use it in the code as well. For that, you need to create the route on web.php and paste the following code.

Chrome - How to Clear Cache
Route::get('/clear-cache', function() {
    Artisan::call('cache:clear');
    Artisan::call('view:clear');
    Artisan::call('route:clear');
    Artisan::call('config:clear');
    // return what you want
});

In the above code, we are creating clear-cache in which we are clearing the cache, views cache, route cache, and config cache.

Now you have to just call the URL in the browser (https://yourdomain.com/clear-cache) to clear the cache.

Conclusion:

Hope you have learned today how to clear cache in Laravel without using the command prompt or terminal.

See you in the next one 🙂

Write a Reply or Comment

Your email address will not be published. Required fields are marked *


Icon