I have 3 tables, a pedido table a product table and a pivot pedido_product. I try to update the cantidad field on the pivot table. I 'm able to with hard coded values
(replied to me in this thread
http://laracasts.com/discuss/channels/laravel/updating-data-on-the-pivot
$productId = 2;
$cantidad = 1.1;
Pedido::find($pedidoId)->products()->updateExistingPivot($productId, [
"cantidad" => $cantidad
]);
Now i have a form where i try to update the cantidad on each product on the same request
{!! Form::open(array('action' => ['PedidosController@update', $pedido->id],'method' => 'PATCH')) !!}
@foreach ($pedido->products as $product)
{!! Form::text($product->pivot->product_id, $product->pivot->cantidad, ['class' => 'form-control' ,'id' => 'cantidad']) !!}
i get what i want, an array with a key refrenced from the product_id and the value of the to be updated cantidad.
but now how do i bind productId and cantidad in the update method to the array i recieve from my form and loop through them in my update method?
$pedido = $request->input();
$productId = ? ;
$cantidad = ? ;
dd($productId);
Pedido::find($pedidoId)->products()->updateExistingPivot($productId, [
"cantidad" => $cantidad
Thanks