Skip to content

Commit 110e8d7

Browse files
sileencetaylorotwell
authored andcommitted
Add the lazy method to delay the creation of models in the database when using model factories (#18823)
1 parent 662f597 commit 110e8d7

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Illuminate/Database/Eloquent/FactoryBuilder.php

+13
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ public function states($states)
102102
return $this;
103103
}
104104

105+
/**
106+
* Create a model and persist it in the database if requested.
107+
*
108+
* @param array $attributes
109+
* @return \Closure
110+
*/
111+
public function lazy(array $attributes = [])
112+
{
113+
return function () use ($attributes) {
114+
return $this->create($attributes);
115+
};
116+
}
117+
105118
/**
106119
* Create a collection of models and persist them to the database.
107120
*

0 commit comments

Comments
 (0)