Skip to content

Commit

Permalink
Allow imploding when instance of Stringable (#34271)
Browse files Browse the repository at this point in the history
  • Loading branch information
leepownall authored Sep 10, 2020
1 parent bffaf8d commit 1b8f0fd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Collections/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down
12 changes: 12 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(','));
}

/**
Expand Down

0 comments on commit 1b8f0fd

Please sign in to comment.