diff --git a/src/Illuminate/Collections/helpers.php b/src/Illuminate/Collections/helpers.php index 5138b2cd1a12..67669e5ce1c6 100644 --- a/src/Illuminate/Collections/helpers.php +++ b/src/Illuminate/Collections/helpers.php @@ -58,7 +58,7 @@ function data_get($target, $key, $default = null) if ($segment === '*') { if ($target instanceof Collection) { $target = $target->all(); - } elseif (! is_iterable($target)) { + } elseif (! is_array($target)) { return value($default); } diff --git a/tests/Support/SupportHelpersTest.php b/tests/Support/SupportHelpersTest.php index 8acc3c7e7d00..bc2d71f19463 100755 --- a/tests/Support/SupportHelpersTest.php +++ b/tests/Support/SupportHelpersTest.php @@ -3,11 +3,9 @@ namespace Illuminate\Tests\Support; use ArrayAccess; -use ArrayIterator; use Illuminate\Contracts\Support\Htmlable; use Illuminate\Support\Env; use Illuminate\Support\Optional; -use IteratorAggregate; use LogicException; use Mockery as m; use PHPUnit\Framework\TestCase; @@ -89,18 +87,10 @@ public function testDataGetWithNestedArrays() ['name' => 'abigail'], ['name' => 'dayle'], ]; - $arrayIterable = new SupportTestArrayIterable([ - ['name' => 'taylor', 'email' => 'taylorotwell@gmail.com'], - ['name' => 'abigail'], - ['name' => 'dayle'], - ]); $this->assertEquals(['taylor', 'abigail', 'dayle'], data_get($array, '*.name')); $this->assertEquals(['taylorotwell@gmail.com', null, null], data_get($array, '*.email', 'irrelevant')); - $this->assertEquals(['taylor', 'abigail', 'dayle'], data_get($arrayIterable, '*.name')); - $this->assertEquals(['taylorotwell@gmail.com', null, null], data_get($arrayIterable, '*.email', 'irrelevant')); - $array = [ 'users' => [ ['first' => 'taylor', 'last' => 'otwell', 'email' => 'taylorotwell@gmail.com'], @@ -802,18 +792,3 @@ public function offsetUnset($offset) unset($this->attributes[$offset]); } } - -class SupportTestArrayIterable implements IteratorAggregate -{ - protected $items = []; - - public function __construct($items = []) - { - $this->items = $items; - } - - public function getIterator() - { - return new ArrayIterator($this->items); - } -}