feat: block destructive DB commands in production

Listen for CommandStarting event and throw RuntimeException for
migrate:fresh, migrate:refresh, migrate:reset, db:wipe, db:seed
when APP_ENV=production. Prevents accidental data loss even with --force.

Also removes old non-functional closure-based override in routes/console.php.
This commit is contained in:
F4ilji
2026-09-18 02:54:42 +05:00
parent 4a776a42e2
commit 7ff860feca
2 changed files with 8 additions and 8 deletions
+8 -1
View File
@@ -27,7 +27,14 @@ class EventServiceProvider extends AbstractEventServiceProvider
*/
public function boot()
{
//
if (app()->environment('production')) {
Event::listen(\Illuminate\Console\Events\CommandStarting::class, function ($event) {
$blocked = ['migrate:fresh', 'migrate:refresh', 'migrate:reset', 'db:wipe', 'db:seed'];
if (in_array($event->command, $blocked)) {
throw new \RuntimeException("BLOCKED: {$event->command} is disabled in production.");
}
});
}
}
/**