Prohibit destructive commands in production
At the end, destructive module commands refuse to run in production, even when passed --force.
-
Call
Module::prohibitDestructiveCommands()in theboot()method of an application service provider. Pass$this->app->isProduction()to block them only in production, or omit the argument to block them in every environment.app/Providers/AppServiceProvider.php use Nwidart\Modules\Facades\Module;public function boot(): void{Module::prohibitDestructiveCommands($this->app->isProduction());} -
Deploy the change to production. When
APP_ENVisproduction, Laravel applies the prohibition during boot.
Which commands are blocked
Section titled “Which commands are blocked”Module::prohibitDestructiveCommands() blocks five commands:
module:migrate-freshmodule:migrate-refreshmodule:migrate-resetmodule:migrate-rollbackmodule:delete
Each command has its own prohibition flag, so you can also block one command on its own (for example MigrateFreshCommand::prohibit()). See Destructive commands.
Other commands stay unaffected. In production, module:migrate and module:seed still require Laravel’s confirmation or --force.
A blocked command prints a warning, runs nothing, and exits with status 1:
WARN This command is prohibited from running in this environment.Run a blocked command on purpose
Section titled “Run a blocked command on purpose”--force skips confirmation prompts only; it does not override a prohibition. To allow an emergency run, gate the prohibition on an environment variable:
Module::prohibitDestructiveCommands( $this->app->isProduction() && ! env('ALLOW_DESTRUCTIVE_COMMANDS', false));Pass the variable in the process environment when running the command:
ALLOW_DESTRUCTIVE_COMMANDS=true php artisan module:migrate-rollback Blog --forceSetting the variable in .env has no effect when configuration is cached.
The production confirmation
Section titled “The production confirmation”Without prohibition, the four destructive migration commands prompt for confirmation in production unless you pass --force:
php artisan module:migrate-fresh --all --forcemodule:delete prompts in every environment unless you pass --force.
Check the result
Section titled “Check the result”In the production environment, run:
php artisan module:migrate-rollback Blog --forceThe command prints This command is prohibited from running in this environment. and exits with status 1.