Skip to content

Instantly share code, notes, and snippets.

@mostafa6765
Forked from Merazsohel/Laravel Cache Clear
Created July 10, 2019 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mostafa6765/93cb938e079f390bf889c18c80fa926b to your computer and use it in GitHub Desktop.
Save mostafa6765/93cb938e079f390bf889c18c80fa926b to your computer and use it in GitHub Desktop.
Laravel Cache Clear
Route::get('artisan/command/{key?}', array(function($key = null)
{
Artisan::call('config:clear');
if($key == "cache-clear")
{
try
{
echo '<br>php artisan cache:clear...';
Artisan::call('cache:clear');
echo '<br>php artisan cache:clear completed';
}
catch (Exception $e) {
Response::make($e->getMessage(), 500);
}
}
elseif($key == "view-clear")
{
try
{
echo '<br>php artisan view:clear...';
Artisan::call('view:clear');
echo '<br>php artisan view:clear completed';
}
catch (Exception $e)
{
Response::make($e->getMessage(), 500);
}
}
else
{
App::abort(404);
}
}
));
//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>';
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment