Prevent catastrophic accidents like db:wipe or migrate:fresh in production using Laravel's Prohibitable trait and DB::prohibitDestructiveCommands().
Accidentally running migrate:fresh on production is every team's nightmare. Laravel provides DB::prohibitDestructiveCommands() to disallow destructive commands in production.
public function boot(): void
{
DB::prohibitDestructiveCommands($this->app->isProduction());
}
- Guards migrate:fresh, migrate:refresh, migrate:reset, and db:wipe
- Configured once in AppServiceProvider::boot()
- Throws command failure exit code if executed in production
Tags:
#Laravel #Database #Security