Skip to content

Commit

Permalink
Fix passing model instances to factories (#35541)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerkretzmar committed Dec 8, 2020
1 parent 91b1279 commit 2058279
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Illuminate/Database/Eloquent/Factories/Factory.php
Expand Up @@ -492,7 +492,11 @@ public function hasAttached($factory, $pivot = [], $relationship = null)
'has' => $this->has->concat([new BelongsToManyRelationship(
$factory,
$pivot,
$relationship ?: Str::camel(Str::plural(class_basename($factory->modelName())))
$relationship ?: Str::camel(Str::plural(class_basename(
$factory instanceof Factory
? $factory->modelName()
: Collection::wrap($factory)->first()
)))
)]),
]);
}
Expand All @@ -508,7 +512,9 @@ public function for($factory, $relationship = null)
{
return $this->newInstance(['for' => $this->for->concat([new BelongsToRelationship(
$factory,
$relationship ?: Str::camel(class_basename($factory->modelName()))
$relationship ?: Str::camel(class_basename(
$factory instanceof Factory ? $factory->modelName() : $factory
))
)])]);
}

Expand Down

0 comments on commit 2058279

Please sign in to comment.