I would like to know how to save checkbox
values inside a while
, the comprar01
o checkbox
field that should return true
or false
.
I get through request()
:
$idproduto=$request->get('idproduto');
$qnt=$request->get('qnt');
$comprar01=$request->get('comprar01');
I make while
in controller
to save in bank
$cont = 0;
while($cont < count($idproduto))
{
$detalhe = new MapaCompraDet();
$detalhe->idmapacompra = $dados->idmapacompra;
$detalhe->idproduto = $idproduto[$cont];
$detalhe->qnt = $qnt[$cont];
$detalhe->comprar01=$comprar01[$cont]; //aqui o problema
$detalhe->save();
$cont = $cont + 1;
Error:
Itriedthis
publicfunctionupdate(Request$request,$id){$dados=MapaCompra::findOrFail($id);$idproduto=$request->get('idproduto');for($i=0;$i<count($idproduto);$i++){$comprar01=(isset($request['comprar01']))?$request['comprar01']:'inativo';dd($comprar01);}
Itbringsmeintheddonlythemarkedones,whennotmilestoneitdoesnotbring.IsearchedhereandsawthatIhavetocheckboxesbeforeentering,I'mtrying.See: link
CODE
<tbodyid="tbodyCotacao">
@foreach($detalhes as $detalhe)
<tr>
<!-- ITENS COTAÇÃO 01 -->
<td>
<input style=" width: 60px" class="form-control" type="number" min="0" name="entrega01[]" value="{{$detalhe->entrega01}}">
</td>
<td>
<input style=" width: 70px" class="form-control" type="text" name="marca01[]" value="{{$detalhe->marca01}}">
</td>
<td>
<input id="pqnt" type="hidden" name="qnt[]" value="{{$detalhe->qnt}}">
<input id="vrunit01" style=" width: 65px;text-align:center" class="form-control" type="text" name="vrunit01[]" value="{{number_format($detalhe->vrunit01, 2, ',', '.') }}" onblur="multiplicar();" onblur="formatar();">
</td>
<td>
<input id="subtotal01" style="text-align:right;width: 75px" class="form-control subtotal01" type="hidden" name="subtotal01[]" readonly onblur="calcular();">
<input style="text-align:right;width: 75px" type="text" class="form-control subtotal01T" id="subtotal01T" value="{{number_format($detalhe->qnt*$detalhe->vrunit01, 2, ',', '.') }}" readonly>
<td style="text-align:center">
<input @if($detalhe->comprar01=='c') {!! 'checked="checked" ' !!}@endif type="checkbox" name="comprar01[]" value="c">
</td></tr>