diff --git a/src/NewCommand.php b/src/NewCommand.php index e245984..19fe84b 100644 --- a/src/NewCommand.php +++ b/src/NewCommand.php @@ -251,14 +251,14 @@ protected function configureDefaultDatabaseConnection(string $directory, string $database = 'mysql'; } - $this->replaceInFile( - 'DB_CONNECTION=sqlite', + $this->pregReplaceInFile( + 'DB_CONNECTION=.*', 'DB_CONNECTION='.$database, $directory.'/.env' ); - $this->replaceInFile( - 'DB_CONNECTION=sqlite', + $this->pregReplaceInFile( + 'DB_CONNECTION=.*', 'DB_CONNECTION='.$database, $directory.'/.env.example' ); @@ -823,4 +823,20 @@ protected function replaceInFile(string|array $search, string|array $replace, st str_replace($search, $replace, file_get_contents($file)) ); } + + /** + * Replace the given string in the given file using regular expressions. + * + * @param string|array $search + * @param string|array $replace + * @param string $file + * @return void + */ + protected function pregReplaceInFile(string $pattern, string $replace, string $file) + { + file_put_contents( + $file, + preg_replace($pattern, $replace, file_get_contents($file)) + ); + } }