Created
November 5, 2024 08:36
-
-
Save Yousha/2683f1976a0d711b80879bd24cecaddd to your computer and use it in GitHub Desktop.
Laravel - clear all caches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* 'composer dump-autoload', | |
'optimize:clear', | |
'queue:restart', | |
'clear-compiled', | |
'session:clear', | |
'tests-storage:clear', | |
'log:clear', | |
'event:clear', | |
'auth:clear-resets', | |
'debugbar:clear' */ | |
# Laravel command | |
class ClearAllCaches extends Command implements Isolatable | |
{ | |
// The name and signature of the console command. | |
protected $signature = 'clear-all-caches'; | |
// The console command description. | |
protected $description = 'Clear all project caches and logs.'; | |
// Execute the console command. | |
public function handle() | |
{ | |
$this->info('Executing clear-all-caches command...'); | |
// Note: `2>&1` tells the shell to redirect the standard error stream(2) to the same place as the standard output stream(1). | |
shell_exec('composer dump-autoload 2>&1'); | |
// Laravel Artisan commands to call. | |
$_commands = [ | |
'optimize:clear', | |
'queue:restart', | |
'clear-compiled', | |
'session:clear', | |
'tests-storage:clear', | |
'log:clear', | |
'event:clear', | |
'auth:clear-resets', | |
'debugbar:clear' | |
]; | |
// Execute the commands using the Laravel Artisan facade. | |
foreach ($_commands as $command) { | |
Artisan::call($command); | |
} | |
$this->info('clear-all-caches execution has finished.'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment