many to many - Updating extra fields pivot table laravel -


i have 3 tables,

a pedido(order) table, product table , pedido_product table have field cantidad in pedido_product table i´m trying update each product orderd

i'm able update fields hardcode values in update method, cantidad get's updated correctly

  $productid = 2;    $cantidad = 1.1;   pedido::find($pedidoid)->products()->updateexistingpivot($productid, [  "cantidad" => $cantidad  ]); 

now have form try update cantidad on each product on same request

 {!! form::open(array('action' =>   ['pedidoscontroller@update', $pedido->id],'method' => 'patch')) !!}  @foreach ($pedido->products $product)  {!! form::text($product->pivot->product_id,    $product->pivot->cantidad, ['class' => 'form-control' ,'id' => 'cantidad']) !!} 

i want, array key refrenced product_id , value of updated cantidad. how bind productid , cantidad in update method array recieve form , loop through them in update method?

  $pedido = $request->input();   $productid =  ? ;   $cantidad = ? ;   pedido::find($pedidoid)->products()->updateexistingpivot($productid, [   "cantidad" => $cantidad 

thanks

edit


i didnn't found ansert changed approach, instead of updating them @ same time, update them 1 one opening form after loop , passing throug hidden form provides product_id trick

 @foreach ($pedido->products $product)  {!! form::open(array('action' => ['pedidoscontroller@update', $pedido->id],'method' => 'patch')) !!}  {!! form::text('cantidad', $product->pivot->cantidad, ['class' => 'form-control']) !!}  {!! form::hidden('id', $product->pivot->product_id, ['class' => 'form-control']) !!} 


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -