Skip to content

Commit

Permalink
Add the lazy method to delay the creation of models in the database w…
Browse files Browse the repository at this point in the history
…hen using model factories (#18823)
  • Loading branch information
sileence authored and taylorotwell committed Apr 17, 2017
1 parent 662f597 commit 110e8d7
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Illuminate/Database/Eloquent/FactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ public function states($states)
return $this;
}

/**
* Create a model and persist it in the database if requested.
*
* @param array $attributes
* @return \Closure
*/
public function lazy(array $attributes = [])
{
return function () use ($attributes) {
return $this->create($attributes);
};
}

/**
* Create a collection of models and persist them to the database.
*
Expand Down

0 comments on commit 110e8d7

Please sign in to comment.