How to insert big data on the laravel? - Stack Overflow

PHOTO EMBED

Tue Aug 03 2021 04:36:57 GMT+0000 (Coordinated Universal Time)

Saved by @mvieira #php

$insert_data = collect();

foreach ($json['value'] as $value) {
    $posting_date = Carbon::parse($value['Posting_Date']);

    $posting_date = $posting_date->format('Y-m-d');

    $insert_data->push([
        'item_no'                   => $value['Item_No'],
        'entry_no'                  => $value['Entry_No'], 
        'document_no'               => $value['Document_No'],
        'posting_date'              => $posting_date,
        ....
    ]);
}

foreach ($insert_data->chunk(500) as $chunk)
{
   \DB::table('items_details')->insert($chunk->toArray());
}
content_copyCOPY

https://stackoverflow.com/questions/51487769/how-to-insert-big-data-on-the-laravel