【发布时间】:2021-04-09 02:35:03
【问题描述】:
您好,我有一行数据,我希望允许用户单击复选框打开/关闭数据以供使用。我已经阅读了https://stackoverflow.com/a/43995087/14936674 的答案,它工作正常,除了我的复选框值只有在被选中时才能更新。如果我想取消选中该框并对其进行更新,则不会对其进行更新。目前我已经通过更新复选框进行了测试,但是它会更新并取消选中我的所有数据。
下面是我的blade.php
<tbody>
@foreach($operatinghrs as $i => $operatinghr)
<tr id="{{ $operatinghr->{'opID'} }}">
<td>
<input type="hidden" name="operatinghrs[{{ $i }}][opID]" value="{{ $operatinghr->{'opID'} }}">{{ $operatinghr->{'day'} }}
</td>
<td>
<input type="time" id="start_time" name="operatinghrs[{{ $i }}][start_time]" min="00:00" max="23:59" value="{{ display24HTime(old('start_time', $operatinghr->start_time))}}">
</td>
<td>
<input type="time" id="end_time" name="operatinghrs[{{ $i }}][end_time]" min="00:00" max="23:59" value="{{ display24HTime(old('end_time', $operatinghr->end_time))}}">
</td>
<td>
<div class="switch">
<input type="checkbox" id="clinic_open" name="operatinghrs[{{ $i }}][clinic_open]" class="switch-input" value="1" {{ old('clinic_open', $operatinghr->clinic_open=="true") ? 'checked="checked"' : '' }}/>
<div class="circle"></div>
</div>
</td>
</tr>
@endforeach
</tbody>
以下是我的控制器类中的代码:
public function update(Request $request)
{
foreach($request->get('operatinghrs', []) as $operatinghr) {
$db = new OperatingHour();
$db->where('opID', $operatinghr['opID'])->where('clinic_id', '=', $_SESSION['clinic_ID'])
->update(
[
'clinic_open' => $request->input('clinic_open') ? true : false,
]
);
}
return back()->with('success_message', 'Details updated successfully!');
}
【问题讨论】: