【发布时间】:2021-01-21 12:05:52
【问题描述】:
我写了一个非常简单的代码来更新复选框的值,但是如果取消选中它在数据库中更新 1 如果请求在这里提交,它不会更新 0 是代码
<div class="form-group">
<label>If it is checked it means user can only create given customer order.</label>
<input type="checkbox" id="js-switch" name="customer_itself" @if($ot->customer_itself == 1) checked @endif>
</div>
控制器端
if ($request->has('customer_itself')) {
if($ot->customer_itself == 1){
$ot->customer_itself = 0;
}else{
$ot->customer_itself = 1;
}
其中有什么错误?
【问题讨论】:
-
我并不精通 laravel,但据我所知,如果我错了,请纠正我,但我认为输入没有任何价值。
-
这是一个复选框,当我们选中它时,它会将值传递给控制器,表明该复选框是触发的,我接受使用 has() 而不是值的触发
-
好的。那么请看下面的答案,这看起来很有希望。
标签: php laravel laravel-5 input checkbox