Prevent catastrophic accidents like db:wipe or migrate:fresh in production using Laravel's Prohibitable trait and DB::prohibitDestructiveCommands().
Accidentally running migrate:fresh or db:wipe on a production database is catastrophic.
Laravel provides DB::prohibitDestructiveCommands() to block dangerous commands when running in production.
AppServiceProvider Configuration
Add the call inside your AppServiceProvider::boot() method:
namespace App\Providers;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
// Block destructive migration commands when in production
DB::prohibitDestructiveCommands(
$this->app->isProduction()
);
}
}
Commands Protected
When prohibited, attempts to run the following commands fail with an exit error code:
php artisan db:wipephp artisan migrate:freshphp artisan migrate:refreshphp artisan migrate:reset
Key Points
- Zero Accidental Overrides: Even passing the
--forceflag cannot bypass a prohibited command. - Environment Driven: Passing
$this->app->isProduction()keeps local, staging, and automated testing environments fully functional.
Related Tips
View all tips →Mask Query Bindings in Laravel Exception Messages
Keep query bindings out of QueryException messages while retaining access to the actual bindings.
Detect AI Agents in Laravel with AgentDetector and PAO
Laravel's AgentDetector detects whether an AI coding agent is interacting with your app, and PAO optimizes CLI output for agents.