@@ -46,6 +46,7 @@ protected function configure()
46
46
->addOption ('branch ' , null , InputOption::VALUE_REQUIRED , 'The branch that should be created for a new repository ' , $ this ->defaultBranch ())
47
47
->addOption ('github ' , null , InputOption::VALUE_OPTIONAL , 'Create a new repository on GitHub ' , false )
48
48
->addOption ('organization ' , null , InputOption::VALUE_REQUIRED , 'The GitHub organization to create the new repository for ' )
49
+ ->addOption ('database ' , null , InputOption::VALUE_REQUIRED , 'The database driver your application will use ' )
49
50
->addOption ('stack ' , null , InputOption::VALUE_OPTIONAL , 'The Breeze / Jetstream stack that should be installed ' )
50
51
->addOption ('breeze ' , null , InputOption::VALUE_NONE , 'Installs the Laravel Breeze scaffolding ' )
51
52
->addOption ('jet ' , null , InputOption::VALUE_NONE , 'Installs the Laravel Jetstream scaffolding ' )
@@ -137,6 +138,7 @@ protected function interact(InputInterface $input, OutputInterface $output)
137
138
*/
138
139
protected function execute (InputInterface $ input , OutputInterface $ output ): int
139
140
{
141
+ $ this ->validateDatabaseOption ($ input );
140
142
$ this ->validateStackOption ($ input );
141
143
142
144
$ name = $ input ->getArgument ('name ' );
@@ -448,8 +450,8 @@ protected function promptForDatabaseOptions(string $directory, InputInterface $i
448
450
{
449
451
$ defaultDatabase = 'sqlite ' ;
450
452
451
- if ($ input ->isInteractive ()) {
452
- $ database = select (
453
+ if (! $ input -> getOption ( ' database ' ) && $ input ->isInteractive ()) {
454
+ $ input -> setOption ( ' database ' , select (
453
455
label: 'Which database will your application use? ' ,
454
456
options: [
455
457
'mysql ' => 'MySQL ' ,
@@ -459,20 +461,19 @@ protected function promptForDatabaseOptions(string $directory, InputInterface $i
459
461
'sqlsrv ' => 'SQL Server ' ,
460
462
],
461
463
default: $ defaultDatabase
462
- );
464
+ )) ;
463
465
464
- if ($ database !== $ defaultDatabase ) {
466
+ if ($ input -> getOption ( ' database ' ) !== $ defaultDatabase ) {
465
467
$ migrate = confirm (label: 'Default database updated. Would you like to run the default database migrations? ' , default: true );
466
468
}
467
469
}
468
470
469
- return [$ database ?? $ defaultDatabase , $ migrate ?? false ];
471
+ return [$ input -> getOption ( ' database ' ) ?? $ defaultDatabase , $ migrate ?? false ];
470
472
}
471
473
472
474
/**
473
475
* Determine the stack for Breeze.
474
476
*
475
- * @param \Symfony\Component\Console\Input\InputInterface $input
476
477
* @return void
477
478
*/
478
479
protected function promptForBreezeOptions (InputInterface $ input )
@@ -554,6 +555,18 @@ protected function promptForJetstreamOptions(InputInterface $input)
554
555
))->each (fn ($ option ) => $ input ->setOption ($ option , true ));
555
556
}
556
557
558
+ /**
559
+ * Validate the database driver input.
560
+ *
561
+ * @param \Symfony\Components\Console\Input\InputInterface
562
+ */
563
+ protected function validateDatabaseOption (InputInterface $ input )
564
+ {
565
+ if ($ input ->getOption ('database ' ) && ! in_array ($ input ->getOption ('database ' ), $ drivers = ['mysql ' , 'mariadb ' , 'pgsql ' , 'sqlite ' , 'sqlsrv ' ])) {
566
+ throw new \InvalidArgumentException ("Invalid database driver [ {$ input ->getOption ('database ' )}]. Valid options are: " .implode (', ' , $ drivers ).'. ' );
567
+ }
568
+ }
569
+
557
570
/**
558
571
* Validate the starter kit stack input.
559
572
*
0 commit comments