LARAVEL Tutorial


Laravel 8 - How To Clear Cache Using Artisan Command

Author:- Shubham Kushwah
Updated Date:-25-09-2020

Laravel 8 Clear Cache using Artisan Command

In your Laravel Application, clear cache easily with these quick and helpful artisan commands.

In this quick tutorial, I will mention few artisan commands you can use to clear various types of cache like config cache, view cache, route cache, and application cache from your laravel application.

This can be useful and sometimes essential while working on your Laravel application.

Clear Cache in Laravel using Terminal

Using Terminal, go to the Laravel application's folder. Then execute the following commands as needed to clear cache from laravel.

  • Clear Application Cache

    To clear laravel application cache, run the following artisan command:

    php artisan cache:clear
  • Clear Route Cache

    To clear route cache of your Laravel application run the following artisan command:

    php artisan route:clear
  • Clear Configuration Cache

    To clear the config cache of your laravel application, run the following artisan command:

    php artisan config:clear
  • Clear Compiled Views Cache

    To clear the view cache of your laravel application which are basically compiled view files, run the following artisan command:

    php artisan view:clear

Sometimes, it's hard to get console access to your laravel application. Thus, it would be easier if we could clear the cache of laravel application through the browser, right? No worries, we can do that too!

Also, this method is useful for users who are using shared hosting for their laravel application! Since it's a bit complex to run artisan commands via the terminal in shared hosting, we can and will use the browser method.

Clear Cache in Laravel using Browser

Here, we are still using the same artisan commands as mentioned above. It's just that, those commands can be run programmatically in Laravel. Thus, we will create special routes to clear cache in Laravel.

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

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

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

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