Skip to content

Commit

Permalink
Defers expanding callables (#42241)
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkGhostHunter authored May 3, 2022
1 parent e8ebcfb commit e040831
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions src/Illuminate/Database/Eloquent/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,21 +447,28 @@ protected function parentResolvers()
*/
protected function expandAttributes(array $definition)
{
return collect($definition)->map(function ($attribute, $key) use (&$definition) {
if (is_callable($attribute) && ! is_string($attribute) && ! is_array($attribute)) {
$attribute = $attribute($definition);
}
return collect($definition)
->map(function ($attribute, $key) {
if ($attribute instanceof self) {
$attribute = $attribute->create()->getKey();
} elseif ($attribute instanceof Model) {
$attribute = $attribute->getKey();
}

if ($attribute instanceof self) {
$attribute = $attribute->create()->getKey();
} elseif ($attribute instanceof Model) {
$attribute = $attribute->getKey();
}
$definition[$key] = $attribute;

$definition[$key] = $attribute;
return $attribute;
})
->map(function ($attribute, $key) use (&$definition) {
if (is_callable($attribute) && ! is_string($attribute) && ! is_array($attribute)) {
$attribute = $attribute($definition);
}

return $attribute;
})->all();
$definition[$key] = $attribute;

return $attribute;
})
->all();
}

/**
Expand Down

0 comments on commit e040831

Please sign in to comment.