Skip to content

Commit

Permalink
Relocate the existence check for factory definitions (#22936)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtvs authored and taylorotwell committed Jan 29, 2018
1 parent 862bb83 commit eea3862
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Illuminate/Database/Eloquent/FactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,15 @@ public function raw(array $attributes = [])
*
* @param array $attributes
* @return mixed
*
* @throws \InvalidArgumentException
*/
protected function getRawAttributes(array $attributes = [])
{
if (! isset($this->definitions[$this->class][$this->name])) {
throw new InvalidArgumentException("Unable to locate factory with name [{$this->name}] [{$this->class}].");
}

$definition = call_user_func(
$this->definitions[$this->class][$this->name],
$this->faker, $attributes
Expand All @@ -238,16 +244,10 @@ protected function getRawAttributes(array $attributes = [])
*
* @param array $attributes
* @return \Illuminate\Database\Eloquent\Model
*
* @throws \InvalidArgumentException
*/
protected function makeInstance(array $attributes = [])
{
return Model::unguarded(function () use ($attributes) {
if (! isset($this->definitions[$this->class][$this->name])) {
throw new InvalidArgumentException("Unable to locate factory with name [{$this->name}] [{$this->class}].");
}

$instance = new $this->class(
$this->getRawAttributes($attributes)
);
Expand Down

0 comments on commit eea3862

Please sign in to comment.