How to clear route, view config cache and re-optimize in shared live hosting server

28 May 2023   724
Comments 4

You can use this example with laravel 6, laravel 7, laravel 8, laravel 9 and laravel 10 versions.
1) Application Cache Clear in Laravel
2) Route Cache Clear in Laravel
3) View Cache Clear in Laravel
4) Config Cache Clear in Laravel
5) Event Cache Clear in Laravel
6) All Cache Clear in Laravel
7) Cache Clear by Route in Laravel

You can try the following route in your Laravel project (routes/web.php):

//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>';
});

//Route cache:
Route::get('/route-cache', function() {
    $exitCode = Artisan::call('route:cache');
    return '<h1>Routes cached</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>';
});


You can try the following php artisan commands:

1) Application Cache Clear in Laravel
php artisan cache:clear

2) Route Cache Clear in Laravel
php artisan route:clear

3) View Cache Clear in Laravel
php artisan view:clear

4) Config Cache Clear in Laravel
php artisan config:clear

5) Event Cache Clear in Laravel
php artisan event:clear

6) All Cache Clear in Laravel
php artisan optimize:clear

7) Cache Clear by Route in Laravel
You can also clear cache without command using route. You have to create a route like bellow:

Route::get('/clear-cache-all', function() {
    Artisan::call('cache:clear');
    dd("Cache Clear All");
});

 

 

 

 

 

 

Comments

  1. Thanks, you solved my problem. I’m sure others will benefit from your expertise.

  2. A big thank you for posting your effective management technique! We’re grateful for your willingness to share your knowledge with others.

  3. That works fine for me and thanks for sharing your helpful trick!
    We appreciate your contribution to our website and community.

  4. Thank you brother with such a perfect and clear guide.

Enter your comment below. Fields marked * are required. You must preview your comment before submitting it.