'Update Quantity of multiple products in one form Laravel

I have an admin panel where I can view and edit orders. In Edit Order section, I have ordered products with pivot quantity. I need to update quantity of each product.

View:

@foreach($products as $product)
 <tr>
  <th>{{ $product->code }}</th>
  <th>{{ $product->name }}</th>
  <td> <input type="number" value="{{ $product->pivot->quantity }}" class="form-control" name="eproduct"></td>
 </tr>
@endforeach

Orders Controller

public function update(Request $request, $id)
    {
$products = array();
        foreach($data->products as $product)
        {
            $products[] = $product->id;
        }
        
        $ordered_products = EorderProduct::where('eorder_id', $id)->whereIn('product_id', $products)->update(array('quantity' => $request->eproduct));
        }

when I do dd($request->eproduct), its showing only the last item quantity. And not updating anything.



Solution 1:[1]

the input should be array

  <td> <input type="number" value="{{ $product->pivot->quantity }}" class="form-control" name="eproduct[]"></td>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ahmed nasser