skip to Main Content

Does any one know how to clear the cache on laravel -9 on server
I tried it and it took me to a 404 error page

Route::get('/clear', function() {

    Artisan::call('cache:clear');
    Artisan::call('config:clear');
    Artisan::call('config:cache');
    Artisan::call('view:clear');
 
    return "Cleared!";
 
 });

and

Route::get('clear',[SiteController::class,'clear']);
public function clear()

    {

    Artisan::call('route:clear');
    Artisan::call('config:clear');
    Artisan::call('config:cache');
    Artisan::call('view:clear');
 
    return "Cleared!";

    }

I have tried these 2 code, both are not working. and My new updates are not showing up on the site also

please help me
Thanks in advance

2

Answers


  1. I think you can add these code to web.php

    Route::get('config', function () {
    Artisan::call('cache:clear');
    Artisan::call('storage:link');
    Artisan::call('view:clear');
    Artisan::call('route:clear');
    Artisan::call('config:clear');
    dd("Success..! OK");});
    
    Login or Signup to reply.
  2. be aware of the danger of this approach, if someone get the url of this route, they could clear your entire server’s cache at will.

    instead use a QueueJob or a Schedule, if your are using CI/CD you can also invoke those command everytime you deploy

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search