diff --git a/src/Illuminate/Database/Console/DbCommand.php b/src/Illuminate/Database/Console/DbCommand.php index 3aee98e2b113..11812e545883 100644 --- a/src/Illuminate/Database/Console/DbCommand.php +++ b/src/Illuminate/Database/Console/DbCommand.php @@ -4,6 +4,7 @@ use Illuminate\Console\Command; use Illuminate\Support\ConfigurationUrlParser; +use Illuminate\Support\Str; use Symfony\Component\Process\Process; use UnexpectedValueException; @@ -52,9 +53,11 @@ public function handle() */ public function getConnection() { - $connection = $this->laravel['config']['database.connections.'. - (($db = $this->argument('connection')) ?? $this->laravel['config']['database.default']) - ]; + [$db, $type] = $this->parseConnectionName( + $this->argument('connection') ?? $this->laravel['config']['database.default'] + ); + + $connection = $this->laravel['config']['database.connections.'.$db]; if (empty($connection)) { throw new UnexpectedValueException("Invalid database connection [{$db}]."); @@ -64,9 +67,27 @@ public function getConnection() $connection = (new ConfigurationUrlParser)->parseConfiguration($connection); } + if (isset($type)) { + $connection = array_merge($connection, $connection[$type]); + } + return $connection; } + /** + * Parse the connection into an array of the name and read / write type. + * + * @param string $name + * @return array + */ + protected function parseConnectionName($name) + { + $name = $name ?: $this->getDefaultConnection(); + + return Str::endsWith($name, ['::read', '::write']) + ? explode('::', $name, 2) : [$name, null]; + } + /** * Get the arguments for the database client command. *