我是 Laravel 的新手,我想将数组数据从 html 表传递到控制器
我曾尝试使用此代码
控制器
foreach($request->input('chk', []) as $key => $chk){
$att = new Attendance;
$att->student_id = $key;
$att->date = $request->att_day;
$status = $chk == 'true' ? 1 : 0;
$att->status = $status;
}
看法
<form action="{{route('attendance.save')}}" method="post" class="form-horizontal form-bordered">
<table class="table">
<thead>
<tr>
<th class="text-center">#</th>
<th>Student Name</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach ($students as $key => $s)
<tr>
<td class="text-center">{{ $key + 1 }}</td>
<td>{{ $s->student_name }}</td>
<td>
<div class="custom-control custom-radio radio-primary">
<input type="radio" id="rdo_{{$key}}_pre" name="rdo[{{$s->id}}]" class="custom-control-input" checked>
<label class="custom-control-label" for="rdo_{{$key}}_pre">Present</label>
</div>
<div class="custom-control custom-radio radio-pink">
<input type="radio" id="rdo_{{$key}}_abs" name="rdo[{{$s->id}}]" class="custom-control-input">
<label class="custom-control-label" for="rdo_{{$key}}_abs">Absent</label>
</div>
</td>
</tr>
@endforeach
</tbody>
</table>
</form>
当我检查传递给控制器的数据时,一切都结束了 0 或者 1根据表中的第一个数据。如何获取视图中选定的 rdo 值
MM们
智慧大石