save big data with laravel

Solutions on MaxInterview for save big data with laravel by the best coders in the world

showing results for - "save big data with laravel"
Ella
19 Feb 2017
1$insert_data = [];
2
3foreach ($json['value'] as $value) {
4    $posting_date = Carbon::parse($value['Posting_Date']);
5
6    $posting_date = $posting_date->format('Y-m-d');
7
8    $data = [
9        'item_no'                   => $value['Item_No'],
10        'entry_no'                  => $value['Entry_No'], 
11        'document_no'               => $value['Document_No'],
12        'posting_date'              => $posting_date,
13        ....
14    ];
15
16    $insert_data[] = $data;
17}
18
19$insert_data = collect($insert_data); // Make a collection to use the chunk method
20
21// it will chunk the dataset in smaller collections containing 500 values each. 
22// Play with the value to get best result
23$chunks = $insert_data->chunk(500);
24
25foreach ($chunks as $chunk)
26{
27   \DB::table('items_details')->insert($chunk->toArray());
28}
Lorenzo
30 May 2019
1ini_set('max_execution_time', 120 ) ; // time in seconds
2
3$insert_data = [];
4
5foreach ($json['value'] as $value)
6{
7   ...
8}