How to Clear Cache in Laravel Applications

June 2, 2023 / General Discussion

In this article, we will explain how to clear the cache in Laravel Applications.

Talking about Laravel as it is an open-source PHP framework that is used to build web applications, and it works on the MVC model-view-controller framework.

While developing Laravel applications, sometimes the code may not reflect. This issue happens due to caching.

You can use two different ways to clear the caches in Laravel, the first one is through the artisan command and the other one is from the browsers.

Here we will understand the steps where you can use to clear different types of caches like view caches, route caches, config caches, and other application caches from your Laravel application.

Follow the steps to Clear Cache in Laravel Using Artisan Commands:

First of all, you need to open your terminal and find your Laravel application’s folder and execute the command:

  1. Clear Views Cache: Run the artisan command given below and get clear and view the cache of your Laravel application:
    php artisan view:clear
  2. Clear Route Cache: Run the artisan command, to clear the route cache of your Laravel application:
    php artisan route:clear
  3. Clear Application Cache: To run the Laravel application cache, executive the following artisan command:
    php artisan cache:clear
  4. Clear Configuration Cache: Run the command, and clear the config cache of your Laravel application:
    php artisan config:clear

Clear the cache in Laravel through a web browser

Run the following commands, to clear the cache through the browser, as it is difficult to get console access to your Laravel application. The following method is easy and simple.

First of all, you have to create specific routes in Laravel, as shown below:

// Clear application cache:

Route::get('/clear-cache', function() {
Artisan::call('cache:clear');
return 'Application cache has been cleared;
});

//Clear route cache:

Route::get('/route-cache', function() {
Artisan::call('route:cache');
return 'Routes cache has been cleared;
});

//Clear config cache:

Route::get('/config-cache', function() {
Artisan::call('config:cache');
return 'Config cache has been cleared;
});

// Clear view cache:

Route::get('/view-clear', function() {
rtisan::call('view:clear');
return 'View cache has been cleared;
});

In this way, you can clear the cache in Laravel using the Artisan command. Also, check our web hosting plans.

Leave a Reply

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