← BACK
Laravel / Configuration

Protect Production with Laravel Prohibitable Commands

Punyapal Shah • • 1 min read
edit this tip →

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:wipe
  • php artisan migrate:fresh
  • php artisan migrate:refresh
  • php artisan migrate:reset

Key Points

  • Zero Accidental Overrides: Even passing the --force flag 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 →
Laravel Configuration

Use config() Instead of env() in Application Code

Call env() only inside configuration files and use config() throughout your application code to prevent missing values when configuration is cached.

READ >

// Got a tip in mind? Contributions are always welcome