Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 1 year ago.
0

Can you show us the loop you created?

Last updated 1 year ago.
0

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

Last updated 1 year ago.
0

move the creating and saving of the model inside the loop as well

Last updated 1 year ago.
0

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...

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

mybigman mybigman Joined 8 Apr 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.