From 9a237e128ea30ceade05099e3776a1bc54a9da6a Mon Sep 17 00:00:00 2001 From: Mohammad Ali Tavassoli Date: Fri, 26 Jan 2018 22:53:24 +0330 Subject: [PATCH] Relocate the existence check for factory definitions --- src/Illuminate/Database/Eloquent/FactoryBuilder.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/FactoryBuilder.php b/src/Illuminate/Database/Eloquent/FactoryBuilder.php index 7a3b0230610d..0fc522c1a109 100644 --- a/src/Illuminate/Database/Eloquent/FactoryBuilder.php +++ b/src/Illuminate/Database/Eloquent/FactoryBuilder.php @@ -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 @@ -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) );