Sure can and these are what i have tried...
// only inserts one record
foreach ($items as $item)
{
$orderItems->fill([
'product_id' => $item->name,
'quantity' => $item->quantity
]);
}
also doing it like this creates an additional query due to the creation of "$orderItems = new OrderItem;"
// doesnt use the order_id that was saved unless i manually add it to the array
foreach ($items as $item)
{
$tmp[] = [
//'order_id' => $order->id,
'product_id' => $item->name,
'quantity' => $item->quantity
];
}
$orderItems->insert($tmp);
thanks
move the creating and saving of the model inside the loop as well
thanks... however this is going to write one query per row instead of doing a bulk insert correct?
on a large number of transactions there would be a performance hit...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community