Hi, I have a snippet code which will take records from one table and add it to a new table. The problem with it is that it will use a lot of memory and it won't work as we have a lot of records.
$chunks = collect($products)->map(function($item){
unset($item->multi_new);
unset($item->subCategoryId);
return (array) $item;
})->chunk(num_of_chunks_here)->toArray();
foreach ($chunks as $chunk) {
DB::table('advirtisments')->insert($chunk);
// maybe even use sleep(number_of_seconds);
}
// if you want to be really thorough at this point:
unset($chunk);
If you cannot use chunk and need to reduce the memory usage you would need to split your two month query into smaller queries e.g. per day and execute in a loop but this hardly seems worth it as chunk is effectively doing the same.