From f7c9895f9b5682b52c8e720bb79a47d966edb870 Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Sun, 4 Oct 2020 12:36:02 +1100 Subject: [PATCH] Support times() with raw() --- src/Illuminate/Database/Eloquent/Factories/Factory.php | 8 +++++++- tests/Database/DatabaseEloquentFactoryTest.php | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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()