diff --git a/src/Illuminate/Collections/Collection.php b/src/Illuminate/Collections/Collection.php index 29aeccfdb419..5edee040f47e 100644 --- a/src/Illuminate/Collections/Collection.php +++ b/src/Illuminate/Collections/Collection.php @@ -512,7 +512,7 @@ public function implode($value, $glue = null) { $first = $this->first(); - if (is_array($first) || is_object($first)) { + if (is_array($first) || (is_object($first) && ! $first instanceof Stringable)) { return implode($glue, $this->pluck($value)->all()); } diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index c59a1e41a5b8..b40e2411193c 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -12,6 +12,7 @@ use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; use Illuminate\Support\LazyCollection; +use Illuminate\Support\Str; use InvalidArgumentException; use JsonSerializable; use Mockery as m; @@ -1784,6 +1785,17 @@ public function testImplode($collection) $data = new $collection(['taylor', 'dayle']); $this->assertSame('taylordayle', $data->implode('')); $this->assertSame('taylor,dayle', $data->implode(',')); + + $data = new $collection([ + ['name' => Str::of('taylor'), 'email' => Str::of('foo')], + ['name' => Str::of('dayle'), 'email' => Str::of('bar')], + ]); + $this->assertSame('foobar', $data->implode('email')); + $this->assertSame('foo,bar', $data->implode('email', ',')); + + $data = new $collection([Str::of('taylor'), Str::of('dayle')]); + $this->assertSame('taylordayle', $data->implode('')); + $this->assertSame('taylor,dayle', $data->implode(',')); } /**