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:
use Illuminate\Console\ConfirmableTrait;
use ConfirmableTrait;
Then, add the function call to the beginning of your handle method:
public function handle(): int
{
// Will only fire on production, or can pass a callback to tell it when to fire
if (! $this->confirmToProceed()) {
return 1;
}
}
Hope this helps!