@@ -204,7 +204,7 @@ protected function getRawAttributes(array $attributes = [])
204204 $ this ->faker , $ attributes
205205 );
206206
207- return $ this ->callClosureAttributes (
207+ return $ this ->expandAttributes (
208208 array_merge ($ this ->applyStates ($ definition , $ attributes ), $ attributes )
209209 );
210210 }
@@ -254,19 +254,25 @@ protected function applyStates(array $definition, array $attributes = [])
254254 }
255255
256256 /**
257- * Evaluate any Closure attributes on the attribute array .
257+ * Expand all attributes to their underlying values .
258258 *
259259 * @param array $attributes
260260 * @return array
261261 */
262- protected function callClosureAttributes (array $ attributes )
262+ protected function expandAttributes (array $ attributes )
263263 {
264264 foreach ($ attributes as &$ attribute ) {
265- $ attribute = $ attribute instanceof Closure
266- ? $ attribute ($ attributes ) : $ attribute ;
265+ if ($ attribute instanceof Closure) {
266+ $ attribute = $ attribute ($ attributes );
267+ }
268+
269+ if ($ attribute instanceof static) {
270+ $ attribute = $ attribute ->create ()->getKey ();
271+ }
267272
268- $ attribute = $ attribute instanceof Model
269- ? $ attribute ->getKey () : $ attribute ;
273+ if ($ attribute instanceof Model) {
274+ $ attribute = $ attribute ->getKey ();
275+ }
270276 }
271277
272278 return $ attributes ;
0 commit comments