简体   繁体   中英

Laravel Blade recursion not working

I a trying to generate page serial with children but not working.

My code

Parent Blade

//index.blade.php
<?php $counter = 0; ?>

@if(isset($items) && count($items))
    @foreach($items as $item)
        <tr class="success">
            <td>{{ ++$counter }}</td>
        </tr>

        @php
            $rows = $item->children()->get();
        @endphp

        @if (count($rows) > 0)
            @include('rows', ['rows' => $rows, 'counter' => $counter])
        @endif
    @endforeach
@endif

Child Blade

//rows.blade.php
@foreach($rows as $row)
    @php
        $titles = $row->getSuperTitle($row);
    @endphp
    <tr>
        <td>{{ ++$counter }}</td>
    </tr>
    @php
        $childRows = $row->children()->get();
    @endphp

    @if (count($childRows) > 0)
        @include('rows', ['rows' => $childRows, 'counter' => $counter])
    @endif
@endforeach

The code return the below view

我看到的结果

But I am Looking for below

在此处输入图片说明

Do not pass $counter to include. Check it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM