mardi 8 mars 2016

Laravel 5.1 Blade - Loop an array until its inner array end

How do i loop an array (directory listing) until it's nothing to loop on Laravel Blade?

Array
(
    [0] => 0.jpg
    [1] => 1.jpg
    [2] => 2.jpg
    [3] => 3.jpg
    [FolderA] => Array
        (
            [0] => A1.jpg
            [1] => A2.jpg
            [FolderB] => Array
                (
                    [0] => B1.jpg
                    [1] => B2.jpg
                    [2] => B3.jpg
                    [3] => B4.jpg
                )
        )

)

On my view.blade.php, I got setup foreach loop on the array, but I'd no idea how to loop the array endlessly.

<ul>
@foreach($dir_files as $dir_name=>$file)
        @if(is_array($file))
           //stuck at here, I cant run a foreach loop inside here right?
           //should I use include?
        @else
            <li>
                <a href="">{{ $file }}</a>
            </li>
        @endif
@endforeach
</ul>

Do we have any method to loop the 3level,5level,10level array endlessly using blade?

I'm sure I can loop the array and precompile the ul li tag inside an array and then echo out on the blade, but may I know do laravel blade has any method that can perform a loop until the inner array ends?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire