/**
* Save an array of new models and attach them to the parent model.
*
* @param \Illuminate\Support\Collection|array $models
* @param array $pivotAttributes
* @return array
*/
public function saveMany($models, array $pivotAttributes = [])
{
foreach ($models as $key => $model) {
$this->save($model, (array) ($pivotAttributes[$key] ?? []), false);
}
$this->touchIfTouching();
return $models;
}
ls -lah /tmp/ | grep sql
-rw-r--r-- 1 vagrant vagrant 2.8M May 12 07:41 bulk.sql
-rw-r--r-- 1 vagrant vagrant 3.9M May 12 07:39 no_bulk_commit.sql
-rw-r--r-- 1 vagrant vagrant 3.9M May 12 07:36 no_bulk_no_commit.sql
time mysql -u root temp < /tmp/bulk.sql
real 0m2.375s
user 0m0.035s
sys 0m0.008s
time mysql -u root temp < /tmp/no_bulk_no_commit.sql
real 1m11.508s
user 0m0.341s
sys 0m0.586s
time mysql -u root temp < /tmp/no_bulk_commit.sql
real 1m0.423s
user 0m0.427s
sys 0m0.589s