diff --git a/src/Illuminate/Database/Eloquent/Factories/Factory.php b/src/Illuminate/Database/Eloquent/Factories/Factory.php index ee0e74440719..9b658295ad8c 100644 --- a/src/Illuminate/Database/Eloquent/Factories/Factory.php +++ b/src/Illuminate/Database/Eloquent/Factories/Factory.php @@ -177,7 +177,13 @@ public function configure() */ public function raw($attributes = [], ?Model $parent = null) { - return $this->state($attributes)->getExpandedAttributes($parent); + if ($this->count === null) { + return $this->state($attributes)->getExpandedAttributes($parent); + } + + return array_map(function () use ($attributes, $parent) { + return $this->state($attributes)->getExpandedAttributes($parent); + }, range(1, $this->count)); } /** diff --git a/tests/Database/DatabaseEloquentFactoryTest.php b/tests/Database/DatabaseEloquentFactoryTest.php index c6a334adf408..e2eaff33f921 100644 --- a/tests/Database/DatabaseEloquentFactoryTest.php +++ b/tests/Database/DatabaseEloquentFactoryTest.php @@ -154,6 +154,14 @@ public function test_expanded_model_attributes_can_be_created() $this->assertSame('Test Title', $post['title']); } + public function test_multiple_model_attributes_can_be_created() + { + $posts = FactoryTestPostFactory::new()->times(10)->raw(); + $this->assertIsArray($posts); + + $this->assertCount(10, $posts); + } + public function test_after_creating_and_making_callbacks_are_called() { $user = FactoryTestUserFactory::new()