@@ -204,7 +204,7 @@ protected function getRawAttributes(array $attributes = [])
204
204
$ this ->faker , $ attributes
205
205
);
206
206
207
- return $ this ->callClosureAttributes (
207
+ return $ this ->expandAttributes (
208
208
array_merge ($ this ->applyStates ($ definition , $ attributes ), $ attributes )
209
209
);
210
210
}
@@ -254,19 +254,21 @@ protected function applyStates(array $definition, array $attributes = [])
254
254
}
255
255
256
256
/**
257
- * Evaluate any Closure attributes on the attribute array .
257
+ * Expand all attributes to their underlying values .
258
258
*
259
259
* @param array $attributes
260
260
* @return array
261
261
*/
262
- protected function callClosureAttributes (array $ attributes )
262
+ protected function expandAttributes (array $ attributes )
263
263
{
264
264
foreach ($ attributes as &$ attribute ) {
265
- $ attribute = $ attribute instanceof Closure
266
- ? $ attribute ($ attributes ) : $ attribute ;
267
-
268
- $ attribute = $ attribute instanceof Model
269
- ? $ attribute ->getKey () : $ attribute ;
265
+ if ($ attribute instanceof Closure) {
266
+ $ attribute = $ attribute ($ attributes );
267
+ } elseif ($ attribute instanceof static) {
268
+ $ attribute = $ attribute ->create ()->getKey ();
269
+ } elseif ($ attribute instanceof Model) {
270
+ $ attribute = $ attribute ->getKey ();
271
+ }
270
272
}
271
273
272
274
return $ attributes ;
0 commit comments