Laravel 8 Clear Cache of Route, View & Config

Share this Article
Reading Time: 4 minutes
2,462 Views

When we do application development in Laravel, as a developer sometimes you have observed that site saves cache of route, view and routes. Due to this, sometime changes doesn’t reflect to pages, sometimes we get the old data on the output screen.

To overcome this issue we are going to see the concept of Laravel 8 Clear cache of route, view & config. These commands are not actually dependent of laravel version. It runs to all application of any version of laravel. These are global artisan commands of laravel.

Inside this tutorial we will see Clear cache of route, view and configuration of laravel application. Laravel provides the list of artisan command which helps to remove complete caches.

Let’s get started.


Laravel Artisan Command Panel

When we open laravel project into terminal and type the command

$ php artisan and press enter, we will get the full list of artisan commands. Have a look we have marked few cache related console commands.


Cache Related Commands

Open laravel application into console and hit these commands according to the need.

Clear Cache

$ php artisan cache:clear

Clear Route Cache

$ php artisan route:cache

Clear View Cache

$ php artisan view:clear

Clear Config Cache

$ php artisan config:cache

These all are command by the help of which we can clear cache of View, Routes & Config. Alternative way to clear caches is by making a route and execute the command. This will do the same function.


Clear Cache by Route – Without Command

Inside this we will create a route into /routes/web.php file. That route when we call, then it clears the cache of the application.

Route::get('clear-all-cache', function() {
  
    Artisan::call('cache:clear');
    dd("Successfully, you have cleared all cache of application.");
});

Behind the scene, it is going to execute the command as

$ php artisan cache:clear

Same we can do for route [ Artisan::call(‘route:cache’); ], views [ Artisan::call(‘view:clear’); ] & config [ Artisan::call(‘config:cache’); ]


Application Testing

Open project to terminal and type the command to start development server

$ php artisan serve

URL- http://localhost:8000/clear-all-cache

We hope this article helped you to learn about Laravel 8 Clear Cache of Route, View & Config Tutorial in a very detailed way.

Buy Me a Coffee

If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.

Find More on Laravel 8 Articles here