DEV Community

Parth Patel
Parth Patel

Posted on • Originally published at parthpatel.net on

Laravel 7: How to 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.

laravel cache clear

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 cache of laravel application through 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 bit complex to run artisan commands via terminal in shared hosting, we can and will use browser method.

Clear Cache in Laravel using Browser

Here, we are still using 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';
 });

Also Read:

The post Laravel 7: How to Clear Cache using Artisan Command appeared first on Parth Patel - a Web Developer.

Top comments (0)