【发布时间】:2018-11-10 15:03:40
【问题描述】:
我有以下文件
{
"_id" : ObjectId("5b1005f8f2468f0fe0007c46"),
"question" : "my question",
"answere" : " my answere",
"options" : [
{
"A" : "dfd"
},
{
"B" : "fdf"
},
{
"C" : "fdfdf"
}
],
"explanation" : "my Explanation",
"correctans" : "A",
"updated_at" : ISODate("2018-05-31T14:26:00Z"),
"created_at" : ISODate("2018-05-31T14:26:00Z")
}
现在我想打印选项,这怎么可能。我正在尝试这个。
@foreach($questions as $key => $question)
<tr>
<td>{{$question->question}}</td>
<td>{{$question->answere}}</td>
<td>{{$question->explanation}}</td>
<td>{{$question->correctans}}</td>
<td>
@foreach($question->options as $key => $option )
{{ $option->A }}
@endforeach
</td>
<td>{{$question->updated_at}}</td>
</tr>
@endforeach
收到此错误
"Trying to get property 'A' of non-object
使用这个获取数据
$questions = Question::all();
请告诉如何获取
【问题讨论】:
-
{{ dd($option) }}的结果是什么? -
数组:1 [▼ "A" => "A" ]
标签: arrays mongodb laravel laravel-5 eloquent