Skip to content

Commit

Permalink
fixed bug when function wrapped around definition of related factory (#…
Browse files Browse the repository at this point in the history
…47168)

* fixed bug when function wrapped around definition of related factory

* formatting

---------

Co-authored-by: Ken van der Eerden <ken@ptchr.nl>
Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
3 people authored May 24, 2023
1 parent 9698de4 commit 03391a4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ protected function expandAttributes(array $definition)
return collect($definition)
->map($evaluateRelations = function ($attribute) {
if ($attribute instanceof self) {
$attribute = $this->getRandomRecycledModel($attribute->modelName())
$attribute = $this->getRandomRecycledModel($attribute->modelName())?->getKey()
?? $attribute->recycle($this->recycle)->create()->getKey();
} elseif ($attribute instanceof Model) {
$attribute = $attribute->getKey();
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/DatabaseEloquentFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ public function definition()
return [
'commentable_id' => FactoryTestPostFactory::new(),
'commentable_type' => FactoryTestPost::class,
'user_id' => FactoryTestUserFactory::new(),
'user_id' => fn () => FactoryTestUserFactory::new(),
'body' => $this->faker->name(),
];
}
Expand Down

0 comments on commit 03391a4

Please sign in to comment.