Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Illuminate/View/Concerns/ManagesLoops.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Illuminate\View\Concerns;

use Countable;
use Illuminate\Support\Arr;
use Illuminate\Support\LazyCollection;

trait ManagesLoops
{
Expand All @@ -22,7 +22,9 @@ trait ManagesLoops
*/
public function addLoop($data)
{
$length = is_array($data) || $data instanceof Countable ? count($data) : null;
$length = is_countable($data) && ! $data instanceof LazyCollection
? count($data)
: null;

$parent = Arr::last($this->loopsStack);

Expand Down
25 changes: 25 additions & 0 deletions tests/View/ViewFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Events\Dispatcher;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\HtmlString;
use Illuminate\Support\LazyCollection;
use Illuminate\View\Compilers\CompilerInterface;
use Illuminate\View\Engines\CompilerEngine;
use Illuminate\View\Engines\EngineResolver;
Expand Down Expand Up @@ -702,6 +703,30 @@ public function testAddingUncountableLoop()
$this->assertEquals([$expectedLoop], $factory->getLoopStack());
}

public function testAddingLazyCollection()
{
$factory = $this->getFactory();

$factory->addLoop(new LazyCollection(function () {
$this->fail('LazyCollection\'s generator should not have been called');
}));

$expectedLoop = [
'iteration' => 0,
'index' => 0,
'remaining' => null,
'count' => null,
'first' => true,
'last' => null,
'odd' => false,
'even' => true,
'depth' => 1,
'parent' => null,
];

$this->assertEquals([$expectedLoop], $factory->getLoopStack());
}

public function testIncrementingLoopIndices()
{
$factory = $this->getFactory();
Expand Down