Skip to content

Blade templates broken when data comes from generator #23624

@acarpio89

Description

@acarpio89
  • Laravel Version: 5.5.37
  • PHP Version: 7.1.6
  • Database Driver & Version: MySQL 5.6.35

Description:

The changes introduced in #23388 break templates that loop over generators:

Exception(code: 0): Cannot traverse an already closed generator at ...

Steps To Reproduce:

In your view composer, or wherever the data for your view is prepared:

while ($someCondition) {
    ...
    yield $results;
}

In your view:

@foreach ($results as $chunk)   <<< This line throws the exception
    @foreach ($chunk as $record)
        ...
    @endforeach
@endforeach

The offending line looks like this in the compiled template:

<?php $__currentLoopData = $results; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $chunk): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions