Sometimes you make commands that you have can potentially run on any environment, but want to confirm the user wants to run it on production.
Laravel does this with its migrate and seed commands:
Laravel has a cool publicly available trait you can use in your commands as well.
Just import the trait:
1use Illuminate\Console\ConfirmableTrait;2 3use ConfirmableTrait;
Then, add the function call to the beginning of your handle method:
1public function handle(): int2{3 // Will only fire on production, or can pass a callback to tell it when to fire4 if (! $this->confirmToProceed()) {5 return 1;6 }7}
Hope this helps!
2,487
views