How to clear cache in Laravel 5

By | August 8, 2020

While working on Laravel projects, sometimes you face an issue that code changes that you are making are not reflecting on the web interface. This issue occurs because pages/interfaces are being served from the cache; therefore, changes are not reflecting on the web interface. To get rid of this type of issue we will have to clear Laravel cache. In this tutorial, I am going to tell you types of cache a Laravel project generates and how to clear these types of cache by using the PHP command-line interface.

A list of Laravel cache clear commands, see below:

Clear Laravel route cache

To clear Laravel route cache, use below commands:

php artisan route:cache

Laravel clear application cache

By using the below command, you will be able to clear the application cache of your project.

php artisan cache:clear

Clear Laravel config cache

If you want to clear your project’s config cache, use the below commands.

php artisan config:cache

Laravel clear view cache

Laravel uses the Blade template engine for view files. To clear view cache run below command in your command-line interface (CLI).

php artisan view:clear

Reoptimized Class

To reoptimize class, you will have to run the below command.

php artisan optimize

Clear Laravel cache from URL

If you are using shared hosting for your project then, you might not have access to SSH; in such condition, you can create a route in your ‘route/web.php’ file and place below code in it. And when you will open the ‘WEBSITE-URL/clear-all-cache’ URL, all cache will be cleared and you will see this message ‘Cache has been successfully cleared’.

Route::get('/clear-all-cache', function() {
    Artisan::call('cache:clear');
    return "Cache has been successfully cleared.";
});

images

Leave a Reply

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