Skip to content

Commit 95a0663

Browse files
committed
extract method
1 parent 1f5822c commit 95a0663

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

src/Illuminate/Database/Eloquent/FactoryBuilder.php

+17-8
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,29 @@ public function create(array $attributes = [])
126126
$results = $this->make($attributes);
127127

128128
if ($results instanceof Model) {
129-
$results->setConnection($results->query()->getConnection()->getName());
130-
131-
$results->save();
129+
$this->store(collect([$results]));
132130
} else {
133-
$results->each(function ($model) {
134-
$model->setConnection($model->query()->getConnection()->getName());
135-
136-
$model->save();
137-
});
131+
$this->store($results);
138132
}
139133

140134
return $results;
141135
}
142136

137+
/**
138+
* Set the connection name on the results and store them.
139+
*
140+
* @param \Illuminate\Support\Collection $results
141+
* @return void
142+
*/
143+
protected function store($results)
144+
{
145+
$results->each(function ($model) {
146+
$model->setConnection($model->query()->getConnection()->getName());
147+
148+
$model->save();
149+
});
150+
}
151+
143152
/**
144153
* Create a collection of models.
145154
*

0 commit comments

Comments
 (0)