【发布时间】:2020-09-10 08:08:46
【问题描述】:
我有一个使用 eloquent 中的 findMany 方法从数据库中提取的集合。 当我 dd 集合时,它看起来像附加的图像。然后我尝试(在我的刀片中) 循环遍历数组中的每个项目,以便能够打印实际记录中的每个值。
$question = Question::whereIn('id', [23,25])->get();
然后在我的刀片中我正在尝试做:
@foreach ($question as $row => $innerArray)
@foreach ($innerArray as $innerRow => $value)
{{$value->question}} //I was expecting "What is your favourite food" here
@foreach ($value->option as $choice)
<li>{{$choice}}</li> //I was expecting the list of the options here
@endforeach
@endforeach
@endforeach
我做错了什么?
【问题讨论】:
-
不应该
{{$value->question}}是 {{$value['question']}} 因为是数组而不是对象属性?@foreach ($value->option as $choice)和$value['options']和 's' 也一样
标签: php laravel loops laravel-blade