If you just need to ask the user for credentials to maintain the database to perform the migration, this can be easily achieved by wrapping the command artisan migratein another command requesting the appropriate credentials. Therefore, it is enough to follow these steps:
1. Create a new command:
artisan make:console MigratePrivilegedCommand --command="migrate:privileged"
2. Add the necessary code to process user input and perform the migrations in the new class of commands:
class MigratePrivilegedCommand extends Command
{
protected $signature = 'migrate:privileged';
protected $description = 'Run migrations as a priviledged database user.';
public function __construct()
{
parent::__construct();
}
public function handle()
{
config([
'database.connections.mysql.username' => $this->ask('What is your username?'),
'database.connections.mysql.password' => $this->secret('What is your password?')
]);
$this->call('migrate');
}
}
3. Register a new command in App\Console\Kernel.php:
protected $commands = [
...
\App\Console\Commands\MigratePrivilegedCommand::class,
];
And now you can start the migration, which requires privileged database credentials:
php artisan migrate:privileged
source
share