Welcome to Laranepal - Nepal's Laravel Community!

Disable Or Override Laravel Migration Commands

Published on July 28, 2025 by

Disable or Override Laravel Migration Commands

🔧 Disable or Override Laravel Migration Commands Using console.php

📌 Introduction

Laravel 11+ introduces a more modular approach for handling Artisan commands via the routes/console.php file. This opens up a clean and convenient way to override or disable default Artisan commands — like migrations — without diving deep into the framework's internals.

In this article, you'll learn how to disable or override Laravel's built-in migration-related commands such as:

  • migrate
  • migrate:fresh
  • migrate:rollback
  • and more...

❓ Why Disable Migration Commands?

In certain production or staging environments, running migration commands could be risky or unnecessary. You might want to:

  • Prevent accidental schema changes.
  • Avoid exposing command-line access to database migration tools.
  • Customize the migration process with logging or constraints.

🛠 Laravel 11/12: Using routes/console.php

In Laravel 11 and 12, you can now register or override Artisan commands directly inside routes/console.php.

🔒 Disable Default Migration Commands

Here’s how to disable all migration commands in one go:

<?php
 
declare(strict_types=1);
 
use Illuminate\Support\Facades\Artisan;
 
// Disable Laravel's default migration commands
collect([
'migrate',
'migrate:fresh',
'migrate:install',
'migrate:refresh',
'migrate:reset',
'migrate:status',
'migrate:rollback',
])->each(function ($command) {
Artisan::command($command, function () use ($command) {
$this->comment("⚠️ {$command} command is disabled.");
})->describe("{$command} command is disabled.");
});

Now when someone runs php artisan migrate, they’ll see a safe message like:

⚠️ migrate command is disabled.

🧩 Customize Instead of Disable

If you’d rather extend the migration behavior (e.g., run extra logic before/after), you can define the command and call the original Artisan class manually:

use Illuminate\Database\Console\Migrations\MigrateCommand;
 
Artisan::command('migrate', function () {
$this->info("Running custom logic before migrate...");
// implement logic
})->describe('Custom wrapper around the migrate command.');

✅ Conclusion

Overriding Artisan commands is now cleaner and safer in Laravel 11 and 12 thanks to the routes/console.php file. Whether you’re securing environments or injecting custom logic, this approach gives you full control over CLI commands — with zero package dependencies or core hacks.


💡 Use Cases

  • Secure production environments
  • Add notifications after migration
  • Wrap commands with logging or conditional logic
  • Train junior devs with safe CLI restrictions

Dinesh Uprety

Senior Software Engineer • Writer @ Laranepal • PHP, Laravel, Livewire, TailwindCSS & VueJS • CEO @ Laranepal & Founder @ laracodesnap

Filed in:

Discussion

Login or register to comment or ask questions

No comments yet

Be the first to share your thoughts or ask a question.

Join the conversation

Sign in to share your thoughts with the community.