Skip to content

Commit

Permalink
extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 18, 2017
1 parent 1f5822c commit 95a0663
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/Illuminate/Database/Eloquent/FactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,29 @@ public function create(array $attributes = [])
$results = $this->make($attributes);

if ($results instanceof Model) {
$results->setConnection($results->query()->getConnection()->getName());

$results->save();
$this->store(collect([$results]));
} else {
$results->each(function ($model) {
$model->setConnection($model->query()->getConnection()->getName());

$model->save();
});
$this->store($results);
}

return $results;
}

/**
* Set the connection name on the results and store them.
*
* @param \Illuminate\Support\Collection $results
* @return void
*/
protected function store($results)
{
$results->each(function ($model) {
$model->setConnection($model->query()->getConnection()->getName());

$model->save();
});
}

/**
* Create a collection of models.
*
Expand Down

0 comments on commit 95a0663

Please sign in to comment.