-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[6.x] Add createMany to factoryBuilder #31171
Conversation
I don't think the "before" is even that bad. It's even fewer LOC. Or to really shorten it, you could do something like this: foreach(['Taylor', 'John', 'Doe'] as $name)
{
factory(User::class)->create(['name' => $name]);
} |
@browner12 it could be multiple columns ! |
This is really surface level thinking, IMO. That's just one example and there are many where I think this would simplify things. It seems along the lines of the recent |
I'm also not a fan of It does not simplify things. It's just a different way to accomplish the same goal. It doesn't significantly reduce lines of code. It does not make the code more readable. It does not make the code more testable. It does not make the code more performant. It's simply different. If you have an example of how it truly simplifies something, would love to hear it so I can reconsider my thinking. -- If you multiple columns try this pattern I've used before: $users = [
'John', 'Doe', 'jdoe@gmail.com',
'Bob', 'Doe', 'bdoe@gmail.com',
'Pete', 'Doe', 'pdoe@gmail.com',
];
foreach($users as $user) {
factory(User::class)->create([
'first_name' => $user[0],
'last_name' => $user[1],
'email' => $user[2],
]);
} |
@browner12 I must say i was surprised that taylor accepted the |
Agree to disagree. 😄 |
I use to push back on all the helpers and such that remove a few keystrokes to do something that is already simple but so many feel differently. Doesn't change my mind but I gave up trying to keep the clutter out of the codebase. |
I've got a little fight left in me. 😄 Really what I'm looking for is for people to justify their PR, not just to say "it simplifies things" and assume that's enough. Tell me why it simplifies things, or show me an example that clearly demonstrates why it's better. |
Create multiple records with custom data !
Before
After
Implementation Notes:
I added
createMany
method toFactoryBuilder
, it loops overcreate
and return an eloquent collection at the end.Thanks!