I have a many-to-many relationship in laravel with a pivot table that joins Products and Orders with an order_product table with the pivot value of Quantity.
Now I am able create the order and add each product in a loop using this:
foreach($products as $product){
$order->products()->save($product,["quantity" => 3]);
}
But, since I have to create entries with hundreds of products, hitting the database for every product does not seem ideal to me, so I'm trying so use this:
$order->products()->saveMany([$product1,$product2,$product3]);
My question is: How, in the second example, using saveMany, can I set the pivot value quantity for each product?