Skip to content

Commit

Permalink
Add mariadb installation option (#292)
Browse files Browse the repository at this point in the history
* Add MariaDB installation option

* Temporary use the Slim Skeleton Branch

* revert to master branch

* Update NewCommand.php

* Update NewCommand.php

* Update NewCommand.php

---------

Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
Jubeki and taylorotwell authored Nov 28, 2023
1 parent 18c134c commit 18101b3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/NewCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ protected function defaultBranch()
*/
protected function configureDefaultDatabaseConnection(string $directory, string $database, string $name)
{
// MariaDB configuration only exists as of Laravel 11...
if ($database === 'mariadb' && ! $this->hasMariaDBConfig($directory)) {
$database = 'mysql';
}

$this->replaceInFile(
'DB_CONNECTION=mysql',
'DB_CONNECTION='.$database,
Expand Down Expand Up @@ -297,6 +302,25 @@ protected function configureDefaultDatabaseConnection(string $directory, string
);
}

/**
* Determine if the application has a MariaDB configuration entry.
*
* @param string $directory
* @return bool
*/
protected function hasMariaDBConfig(string $directory): bool
{
// Laravel 11+ has moved the configuration files into the framework...
if (! file_exists($directory.'/config/database.php')) {
return true;
}

return str_contains(
file_get_contents($directory.'/config/database.php'),
"'mariadb' =>"
);
}

/**
* Install Laravel Breeze into the application.
*
Expand Down Expand Up @@ -368,6 +392,7 @@ protected function promptForDatabaseOptions(InputInterface $input)
label: 'Which database will your application use?',
options: [
'mysql' => 'MySQL',
'mariadb' => 'MariaDB',
'pgsql' => 'PostgreSQL',
'sqlite' => 'SQLite',
'sqlsrv' => 'SQL Server',
Expand Down

0 comments on commit 18101b3

Please sign in to comment.