How to save the input radio inside a table Laravel

0

Howtogiveanupdateonthebankincasetheid=54updatingtheradioinputsmeetwithvalue=a/buywithvalue=c.

Note:

  

Thisisapurchaserequisitionmadebytheuser,Iwouldliketogive  anupdateonlyinthefieldservedaccordingtoinputradio  above.

@foreach($detalhesas$detalhe)<tr><td><divclass="col-xs-6">
                          Atender <input type="radio" name="atendecompra[{{ print $i}}]" value="a" checked="true"> 
                          </div>
                           <div class="col-xs-6">
                          Comprar<input type="radio" name="atendecompra[{{ print $i}}]" value="c">
                          </div>
                      </td>                         
                     </tr>
                      <?php $i++;?>
                      @endforeach

Controllher

public function update(Request $request, $id){


       $idproduto=$request->get('idproduto');
      $atendecompra=$request->get('atendecompra'); 
       $cont = 0;
        while($cont < count($idproduto)){
          $detalhe = new RequisicaoDet();
          $detalhe->idrequisicao=$id;          
          $detalhe->atendecompra=String($atendecompra)[$cont];                  
          $detalhe->update();
          $cont=$cont+1;
        }
         return Redirect::to('almoxarifado/requisicao');
      }

Model

class RequisicaoDet extends Model
{
   protected $table         ='requisicaodet';
   protected $primaryKey    ='idrequisicaodet';
   public $timestamps       =false;
   protected$fillable       =[
   'idrequisicao',
   'idproduto',
   'qnt',
   'detalhe',
   'idcentrocusto',
   'atendecompra'
    ];
   protected $guarded       =[];
}
    
asked by anonymous 24.10.2018 / 17:29

1 answer

0

To update the Model instance in Laravel, you can use the following syntax:

RequisicaoDet::find($id)->update([
  'atendecompra' => $request->get('atendecompra')
]);

It was not very clear why you did this while there with idproduto , but with the above command it will solve your question, which is how to update atendecompra to the specific id.

If there is any doubt, say that I will improve the answer.

    
24.10.2018 / 21:41