Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] createMany & createManyQuietly add count argument #48048

Merged
merged 1 commit into from
Aug 14, 2023

Conversation

JHWelch
Copy link
Contributor

@JHWelch JHWelch commented Aug 11, 2023

Adds the ability to pass an int to the createMany and createManyQuietly functions on Model Factories to create that number of models..

// Before: $users = User::factory()->createMany([[], [], []]);
$users = User::factory()->createMany(3);

$this->assertCount(3, $users);
$this->assertInstanceOf(Eloquent\Collection::class, $users);

createMany is useful for static typing because it always returns an Eloquent Collection, similar to how the createOne method always returns a single model. However currently you must pass an array of argument arrays. This change allows you to pass a count of the total records you want generated instead.

I could look at doing this with the normal create mechanism and confirming the type, but this seemed the most straight forward approach.

@JHWelch JHWelch changed the title createMany & createManyQuietly add count argument [10.x] createMany & createManyQuietly add count argument Aug 11, 2023
@taylorotwell taylorotwell merged commit 2d3fdc0 into laravel:10.x Aug 14, 2023
@JHWelch JHWelch deleted the factory-createmany-pass-count branch August 14, 2023 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants