在Laravel嵌套的foreach

时间:2016-12-23 20:27:31

标签: laravel foreach nested

在我的代码中,我有一个嵌套的foreach,但在运行时会显示此错误Screenshot of error message

这是我的代码:

@foreach ($product as $user)

<p>This is title {{ $user->title }}</p>
<p>This is category {{ $user->category }}</p>
<p>This is sub category {{ $user->sub_category }}</p>

@foreach ($product_image as $product_image)
<p>This is image {{ $product_image->p_image }}</p>
@endforeach

@endforeach

1 个答案:

答案 0 :(得分:1)

第二个foreach应该是:

@foreach ($User->product_images as $product_image)

不是:

@foreach ($product_image as $product_image)