Home:ALL Converter>Laravel - nested foreach loop

Laravel - nested foreach loop

Ask Time:2019-11-22T02:55:07         Author:Toolbox

Json Formatter

I am trying to move a webapp CRUD solution created outside a framework, and now move it inside of Laravel. Below you see the section "standard PHP" which is a code that works, and the "Laravel that does not work.

Question: How do I write nested foreach loops in Laravel as identical as the one written in standard PHP example ?

Laravel

<table>

    <!-- https://laravel.com/docs/5.7/blade#loops -->

    @foreach ($response_body as $key => $value)
        @foreach ($value as $level2data => $array)

    <tr>
        <td>
           Hello
        </td>
    </tr>

        @endforeach
    @endforeach

</table>

Result of laravel code (printout on browser):

@foreach ($response_body as => $value) 
    @foreach ($value as $level2data => array) 

    @endforeach 
@endforeach
Hello 

Standard PHP

<table>        

<?php foreach ($response_body as $key => $value):?>
        <?php foreach ($value as $level2data => $array):?>

    <tr>
        <td id="email">
            <?php echo "hello" . "\r\n"; ?>
       </td>
    </tr>
    <?php endforeach; ?>
<?php endforeach; ?>

</table>

Author:Toolbox,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/58981890/laravel-nested-foreach-loop
yy