Repository: laravel/framework (php)

Issue:
[8.x] schema:dump causes error when using read and write connections in pgsql driver
<!-- DO NOT THROW THIS AWAY -->
<!-- Fill out the FULL versions with patch versions -->

- Laravel Version: 8.35.1
- PHP Version: 7.4.16
- Database Driver & Version: pgsql

### Description:
```
'pgsql' => [
            'read' => [
                'host' => explode(',', env('DB_HOST_READ', '127.0.0.1')),
            ],
            'write' => [
                'host' => explode(',', env('DB_HOST_WRITE', '127.0.0.1')),
            ],
```

php artisan schema:dump causes error:
`[2021-04-05 14:02:09] local.ERROR: Array to string conversion {"exception":"[object] (ErrorException(code: 0): Array to string conversion at /var/www/vendor/symfony/process/Process.php:339)`

Process.php:339
```
        $envPairs = [];
        foreach ($env as $k => $v) {
            if (false !== $v) {
                $envPairs[] = $k.'='.$v; // 339
            }
        }
```

Trying to dump $env inside Process.php
```
dd($env);
array:74 [
  "LARAVEL_LOAD_HOST" => array:1 [
    0 => "host.docker.internal"
  ]

```

### Steps To Reproduce:
1. Set read and write connections in database.php
2. Run php artisan schema:dump
3. Get error

Pull request:
[8.x] fix PostgreSQL schema:dump when read/write hosts are arrays
PostgreSQL schema:dump fails when read/write connection hosts are arrays

Closes #36875

Patch:
diff --git a/src/Illuminate/Database/Schema/PostgresSchemaState.php b/src/Illuminate/Database/Schema/PostgresSchemaState.php
index c844ec542e..ea627a5e0b 100644
--- a/src/Illuminate/Database/Schema/PostgresSchemaState.php
+++ b/src/Illuminate/Database/Schema/PostgresSchemaState.php
@@ -70,8 +70,10 @@ protected function baseDumpCommand()
      */
     protected function baseVariables(array $config)
     {
+        $config['host'] = $config['host'] ?? '';
+
         return [
-            'LARAVEL_LOAD_HOST' => $config['host'],
+            'LARAVEL_LOAD_HOST' => is_array($config['host']) ? $config['host'][0] : $config['host'],
             'LARAVEL_LOAD_PORT' => $config['port'],
             'LARAVEL_LOAD_USER' => $config['username'],
             'LARAVEL_LOAD_PASSWORD' => $config['password'],
diff --git a/src/Illuminate/Support/Facades/Bus.php b/src/Illuminate/Support/Facades/Bus.php
index ec95d86243..4be212e5cf 100644
--- a/src/Illuminate/Support/Facades/Bus.php
+++ b/src/Illuminate/Support/Facades/Bus.php
@@ -16,6 +16,7 @@
  * @method static bool|mixed getCommandHandler($command)
  * @method static mixed dispatch($command)
  * @method static mixed dispatchNow($command, $handler = null)
+ * @method static mixed dispatchSync($command, $handler = null)
  * @method static void assertDispatched(string|\Closure $command, callable|int $callback = null)
  * @method static void assertDispatchedTimes(string $command, int $times = 1)
  * @method static void assertNotDispatched(string|\Closure $command, callable|int $callback = null)
diff --git a/src/Illuminate/Support/Str.php b/src/Illuminate/Support/Str.php
index e8e9975b47..db2656483e 100644
--- a/src/Illuminate/Support/Str.php
+++ b/src/Illuminate/Support/Str.php
@@ -491,6 +491,18 @@ public static function random($length = 16)
         return $string;
     }
 
+    /**
+     * Repeat the given string.
+     *
+     * @param  string  $string
+     * @param  int  $times
+     * @return string
+     */
+    public static function repeat(string $string, int $times)
+    {
+        return str_repeat($string, $times);
+    }
+
     /**
      * Replace a given value in the string sequentially with an array.
      *
diff --git a/src/Illuminate/Support/Stringable.php b/src/Illuminate/Support/Stringable.php
index de9c8b6983..5085a3b876 100644
--- a/src/Illuminate/Support/Stringable.php
+++ b/src/Illuminate/Support/Stringable.php
@@ -479,6 +479,17 @@ public function remove($search, $caseSensitive = true)
         return new static(Str::remove($search, $this->value, $caseSensitive));
     }
 
+    /**
+     * Repeat the string.
+     *
+     * @param  int  $times
+     * @return static
+     */
+    public function repeat(int $times)
+    {
+        return new static(Str::repeat($this->value, $times));
+    }
+
     /**
      * Replace the given value in the given string.
      *


Test patch:
diff --git a/tests/Support/SupportStrTest.php b/tests/Support/SupportStrTest.php
index dc8ec88b5f..f120708968 100755
--- a/tests/Support/SupportStrTest.php
+++ b/tests/Support/SupportStrTest.php
@@ -531,6 +531,12 @@ public function testMarkdown()
         $this->assertSame("<p><em>hello world</em></p>\n", Str::markdown('*hello world*'));
         $this->assertSame("<h1>hello world</h1>\n", Str::markdown('# hello world'));
     }
+
+    public function testRepeat()
+    {
+        $this->assertSame('aaaaa', Str::repeat('a', 5));
+        $this->assertSame('', Str::repeat('', 5));
+    }
 }
 
 class StringableObjectStub
diff --git a/tests/Support/SupportStringableTest.php b/tests/Support/SupportStringableTest.php
index 857d6402da..be88413d75 100644
--- a/tests/Support/SupportStringableTest.php
+++ b/tests/Support/SupportStringableTest.php
@@ -602,4 +602,10 @@ public function testMarkdown()
         $this->assertEquals("<p><em>hello world</em></p>\n", $this->stringable('*hello world*')->markdown());
         $this->assertEquals("<h1>hello world</h1>\n", $this->stringable('# hello world')->markdown());
     }
+
+    public function testRepeat()
+    {
+        $this->assertSame('aaaaa', (string) $this->stringable('a')->repeat(5));
+        $this->assertSame('', (string) $this->stringable('')->repeat(5));
+    }
 }