Answer the question
In order to leave comments, you need to log in
Collections and Bulk Populating a Table?
Good afternoon, kind and knowledgeable people, help me figure it out, I can’t insert a collection into an array in the database,
$collection = collect($name);
foreach($collection->chunk(1000) as $c_id_group){ // set the optimal value
Auto::insert($c_id_group->toArray());
usleep(100); // set pause value in microseconds
}
id
c_id_group
name_group
Answer the question
In order to leave comments, you need to log in
In general, the request is Auto::insert($c_id_group->toArray()); puts the values of the keys of the array in the column names, so I got completely confused, how can I write the keys in one column and the values \u200b\u200bin the other
$c_id_group->map(function($item, $key){
return [
'field1' => $key,
'field2' => $item
];
})->toArray();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question