pimous
1234
2
Laravel

Return two-dimensional array

Posted 3 years ago by pimous

Hello everyone,

I'd like to display pictures with title. So I need a two-dimensional array. The problem is how to return this array in my view and how to do a foreach with the array.

ProductController.php

$pictures = array();
foreach ($product->pictures as $picture)
        {
             $pictures["link"][] = $picture->link;
             $pictures[]["title"] = $picture->title;
        }
return view('page/showProduct', compact('product','pictures'));

showProduct.blade.php

@foreach($pictures as $picture)
                       <img src="{!! $picture[link] !!}" alt="{!! $picture[title] !!}">
@endforeach

Please sign in or create an account to participate in this conversation.