Today, We are going to learn about Laravel clear cache. Laravel create the cache of Route, View, Config file data. When I working on a project suddenly I get a fatal error on Laravel view file. After, Resolving that issue on view file I see the error still exists in the view file. The issue is the Laravel cache my view file. I resolve that issue by clearing Laravel cache. So, I want to share with you How to clear laravel cache.

We can clear Laravel cache using artisan command using two ways.

Laravel Clear cache using Artisan Command

We are going to clear Laravel cache using Artisan command

Reoptimized class loader

php artisan optimize

Clear Facade Value

php artisan cache:clear

Laravel Clear Route Cache

php artisan route:clear

Laravel Clear View Cache

php artisan view:clear

Laravel clear Config Cache

php artisan config:cache

Finally, We are learning Laravel clear cache using artisan command. But how to clear Laravel cache when we are using shared hosting. Because Shared hosting doesn’t provide command line interface. So, Let’s see how we can clear Laravel cache on shared hosting.

Laravel Clear cache in shared hosting server

We are going to learn about Laravel clear cache in shared hosting server by Laravel Route using Artisan Command

//Clear Cache facade value:
Route::get('/clear-cache', function() {
    $exitCode = Artisan::call('cache:clear');
    return '<h1>Cache facade value cleared</h1>';

//Reoptimized class loader:
Route::get('/optimize', function() {
    $exitCode = Artisan::call('optimize');
    return '<h1>Reoptimized class loader</h1>';

//Clear Route cache:
Route::get('/route-clear', function() {
    $exitCode = Artisan::call('route:clear');
    return '<h1>Route cache cleared</h1>';

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

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

Now, You just need to call route URL for clearing cache on shared hosting.