@foreach ($questions as $question)
<div class="form-group">
<label><strong>{{ $question->activityQuestion_text }}</strong></label>
<div class="input-group">
<div class="icheck-inline">
{{ Form::radio($question->id, 1, false, ['class' => 'icheck']) }}Yes
{{ Form::radio($question->id, 2, false, ['class' => 'icheck']) }}Partial
{{ Form::radio($question->id, 0, false, ['class' => 'icheck']) }}No
</div>
</div>
</div>
@endforeach
此代码块为我提供了以下输出
我想从数据库值中检查这些单选按钮。来自数据库 我得到这5个问题的检查值
@foreach($activity->questions as $flag) {
$flag->pivot->activityAnswer
}
如何在单选按钮循环中使用该值来检查如下
{{ Form::radio($question->id, 1, $flag->pivot->activityAnswer_flag==1, ['class' => 'icheck']) }}Yes
{{ Form::radio($question->id, 2, $flag->pivot->activityAnswer_flag==2, ['class' => 'icheck']) }}Partial
{{ Form::radio($question->id, 0, $flag->pivot->activityAnswer_flag==0, ['class' => 'icheck']) }}No
答案 0 :(得分:0)
目前还不清楚你在这里做了什么,但我会对此采取行动。在这里做最好的方法似乎是使用for
循环而不是foreach
。例如:
@for($i=0; $i < count($questions); $i++)
<label>{{ $questions[$i]->activityQuestion_text }}</label>
{{ Form::radio($questions[$i]->id, 0, $flags[$i]->activityFlag==0, ['class' => 'icheck']) }}Yes
{{ Form::radio($questions[$i]->id, 1, $flags[$i]->activityFlag==0, ['class' => 'icheck']) }}Partial
{{ Form::radio($questions[$i]->id, 2, $flags[$i]->activityFlag==0, ['class' => 'icheck']) }}No
@endfor
希望我能理解你的问题。干杯!