我有带有复选框的表格
@foreach($accounts as $acc)
<input type="checkbox" value="1" name="account[{{ $acc->id }}]" @if($acc->published) checked @endif>
@endforeach
当复选框未选中时如何传递 0 值?
我的控制器:
public function updateMon(Request $request) {
$request->validate([
'account' => 'required|array',
'account.*' => 'integer'
]);
foreach($account as $acc => $val) {
dd($val); //how get 0?
}
}
复选框仅在选中时发布,因此在控制器中您可以使用此片段
public function updateMon(Request $request) {
$request->validate([
'account' => 'required|array',
'account.*' => 'integer'
]);
$myVar = isset($request->account[0]) ? 1 : 0;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)