如何使用刀片中的foreach在idquestion为2的地方显示答案
{"id":1,"answer":"answer1","idquestion":2}
{"id":2,"answer":"answer2","idquestion":2}
{"id":3,"answer":"answer3","idquestion":3}
在控制器中
$Question= Question::select()->get();
$Answer= Answer::select()->get();
return view('Question.ListQuestion ',compact('Question','Answer'));
在ListQuestion刀片服务器中
@foreach($Question as $question)
<tr>
<td>{{$question['thequestion']}}<br>
@if($question->menu=="Checkbox")
@foreach($Answer as $answer)
<input type="checkbox" name="
{{$answer['id']}}"value="{{$answer['id']}}">
{{$answer['theanswer']}}
<br>
@endforeach
@endif
</td>
</tr>
@endforeach
答案 0 :(得分:0)
我可能是错的,但这是您要寻找的东西吗
@foreach($Answer as $answer)
@if($answer->idQuestion == 2 )
<input type="checkbox" name="{{$answer->id}}" value="{{$answer->id}}">
{{$answer->answer}}
<br>
@endif
@endforeach