我从数据库加载复选框,它们是否被选中,
<div class="row">
<div class="col-xs-12">
<div class="form-group">
@php
$json = $orders->data;
$json = json_decode($json, true);
$products = $json['order_info']['products'];
$data = '';
foreach ($products as $hitsIndex => $hitsValue) {
$data .= $hitsValue['type']. ', ';
}
$data = rtrim($data, ', ');
$agosProducts = Utility::constant('agos_products1');
@endphp
{{Html::validation($orders, 'product')}}
<label for="products" class="control-label">{{Translator::transSmart('app.Products', 'Products')}}</label><br><br>
@foreach($agosProducts as $product)
<label class="control-label "for="{{ $product['type'] }}">
<input id="{{ $product['type'] }}" name="{{ $product['type'] }}" type="checkbox" value="{{ $product['type'] }}"
@foreach ($products as $hitsIndex => $hitsValue)
@if(in_array($hitsValue['type'], $product)) checked=checked @endif
@endforeach
>
{{ $product['name'] }}
</label>
<br>
@endforeach
</div>
</div>
</div>
现在我想根据复选框值更新我的数据库。
例如,如果说我从数据库中加载复选框 1,而现在它未选中,我需要在数据库中更新它。
此代码我可以获得复选框的所有当前状态,但我不知道此代码的先前值。因此很难更新当前值的状态并在数据库中添加新状态,
$chks = array('multicolor','resizable','showRuler','namesNumbersEnabled');
foreach ($chks as $chk) {
$product->setAttribute($chk, (Input::has($chk)) ? true : false);
}
这是我保存在数据列中的 json 对象
我加载 [order_info][products][type] 作为检查的产品,同时我从 env 文件加载所有产品。我只需要将选中的复选框产品保存在数据库中。
有人可以帮助我吗?
胡子哥哥