In this episode, we take a look at how Laravel lets you prevent destructive database commands (the ones that could wipe out your data) from running in sensitive environments, like production. First, you'll see how Laravel already has built-in warnings and confirmation prompts if you try to do something risky like rolling back migrations in production. By default, it tries to keep you safe, but you can take this a step further.
You'll learn how to use the DB::prohibitDestructiveCommand()
method, usually in your AppServiceProvider
, to completely block these kinds of commands in production (or any other condition you want). This means that commands like migrate:rollback
simply won't run at all, with Laravel throwing a warning instead of even letting you confirm.
Finally, we talk about a recent update: the rollback
command has now been officially added to the list of commands considered destructive, so it's covered by this protection out of the box along with commands like wipe
, reset
, refresh
, and fresh
. If you didn't know about this feature before, now you do—and you can use it to keep your production database safer!