Clearning Cache in Laravel 8/9

In this tutorial, we will show you how to clear cache using code as well as using command via terminal in a Laravel application.

Clearing Cache using Code

To clear cache in Laravel using code, you can create a function as shown in the example below:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Artisan;

class UserController extends Controller
{
    
    public function clearCache()
    {
       Artisan::call('cache:clear');
    }
}

Clearing Configuration Cache

To clear Laravel configuration cache, you can navigate to the application root folder and run the following command via terminal:


php artisan config:clear

Clearing View Cache

To clear Laravel view cache, you can navigate to the application root folder and run the following command via terminal:


php artisan view:clear

Clearing Route Cache

To clear Laravel route cache, you can navigate to the application root folder and run the following command via terminal:


php artisan route:clear

Clearing Application Cache

To clear Laravel application cache, you can navigate to the application root folder and run the following command via terminal:


php artisan cache:clear