Laravel Clear Cache Using Artisan Command (CLI)

Laravel Clear Cache Using Artisan Command (CLI)

Simply clear cache from the command line (CLI), In this laravel tutorial, we will discuss how to clear cache from blade (views), routes, config, etc using the command line and artisan command.

When our app is product mode (live), we need to make cache in larva projects for better completion. But if our application is development mode then what we want to do is not get cured due to the cache. At this time we need to clear the cache.

List of the cache clear commands, see below

Clear Route Cache

Use the below command and clear your routes cache :

php artisan route:cache

Clear Cache Laravel Application

Use the below command and clear your application cache :

php artisan cache:clear

Laravel Clear Config Cache

Use the below command and clear your config cache :

php artisan config:cache

Clear View Cache Laravel

Use the below command and clear your view (blade) cache :

php artisan view:clear

Reoptimized Class

php artisan optimize

We do not access SSH on shared hosting servers, then we can also clear the cache by typing the code in route file. Go to your web.php file and put below code for clear cache of your application :

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

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

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

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

You may like

  1. Php Artisan Serve Not Working Properly – Laravel Command
  2. Laravel 6 Make Auth (Artisan Command)
  3. Laravel 6 Artisan Console Command Cheat Sheet ( List )
  4. Check Laravel Version Command-Line (cmd) and File
  5. How to Create a Controller And Model Laravel 6 Using cmd
  6. Laravel create and use middleware command

One reply to Laravel Clear Cache Using Artisan Command (CLI)

  1. Thanks for this clear cache in laravel post, I have to clear the cache on shared using this article.

    All the commands for clear cache in laravel ars very useful for me.

    laravel clear cache shared hosting
    laravel clear cache config
    laravel clear cache command line
    laravel clear cache without artisan

    Thanks

Leave a Reply

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