diff --git a/src/Illuminate/Database/Eloquent/Factories/BelongsToManyRelationship.php b/src/Illuminate/Database/Eloquent/Factories/BelongsToManyRelationship.php index eb3e1ee41962..6395b28e02a2 100644 --- a/src/Illuminate/Database/Eloquent/Factories/BelongsToManyRelationship.php +++ b/src/Illuminate/Database/Eloquent/Factories/BelongsToManyRelationship.php @@ -3,6 +3,7 @@ namespace Illuminate\Database\Eloquent\Factories; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Collection; class BelongsToManyRelationship { @@ -50,7 +51,7 @@ public function __construct(Factory $factory, $pivot, $relationship) */ public function createFor(Model $model) { - $this->factory->create([], $model)->each(function ($attachable) use ($model) { + Collection::wrap($this->factory->create([], $model))->each(function ($attachable) use ($model) { $model->{$this->relationship}()->attach( $attachable, is_callable($this->pivot) ? call_user_func($this->pivot, $model) : $this->pivot