Artisan::call method in Laravel is not working

Viewed 85

I created a button for the user to be able to clear cache routes and views.

<div class="col-6">
    <a href="{{route('cache.clear')}}" class="btn btn-outline-primary">clear cache</a>
</div>

I'm using Artisan::call but it does not work. Where is my problem?

Route::get('/clearcache', function() {
    Artisan::call('view:clear');
    Artisan::call('cache:clear');
    Artisan::call('route:clear');

    return show_message(true, 'clear cache  ');
})->name('cache.clear');
1 Answers

If I remove the show_message() function, your code works.

Route::get('/clearcache', function() {
    Artisan::call('view:clear');
    Artisan::call('cache:clear');
    Artisan::call('route:clear');
})->name('cache.clear');

Change the route, run php artisan serve. Then hit the route directly in your browser: http://127.0.0.1:8000/clearcache

Another option...

php artisan optimize:clear

Artisan::call('optimize:clear');

This will return you the following.

Compiled views cleared!
Application cache cleared!
Route cache cleared!
Configuration cache cleared!
Compiled services and packages files removed!
Caches cleared successfully!

All cache types that exist in your Laravel application will be cleared entirely, except Events cache.

Related