Every night I hit my provider for an array of calls that are around 1-2k rows per night. I need to store these with eloquent but im not sure the best way to get this done. Im guessing a foreach to do $call = new calls; $call->date = $date; $call->duration = $duration; $call->moreStuff = $moreStuff;
$call->save(); for a few thousand iterations is not the best approach, any ideas?
1 switch KEY OFF/ON for table before and after inserting 2 use \DB::insert() instead of \Eloquent
Why do you need to store it uing Eloquent? Yes, it's not the best approach, it will be time and resource consuming.
The best way would be inserting in chunks using simple insert
method:
foreach ($chunks as $chunk)
{
DB::table('your_table')->insert($chunk); // single insert query
}
If you have 1k rows to insert, I suppose you can do it in one go, but for more I would do it like above.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community