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

Add macroable to FactoryBuilder class #19425

Merged
merged 1 commit into from
May 31, 2017
Merged

Add macroable to FactoryBuilder class #19425

merged 1 commit into from
May 31, 2017

Conversation

jerguslejko
Copy link
Contributor

@jerguslejko jerguslejko commented May 31, 2017

This PR adds Macroable trait to the Illuminate\Database\Eloquent\FactoryBuilder class.

In my projects, I often use this bit of code inside of model factories:

'user_id' => function() {
    return User::first()->id ?? factory(User::class)->create()->id;
},

If macros were available, the above code could look more like this:

'user_id' => factory(User::class)->firstOrCreate(),

What do you think? 🌵

@taylorotwell taylorotwell merged commit 67de1d6 into laravel:5.4 May 31, 2017
@jerguslejko jerguslejko deleted the factory-builder branch May 31, 2017 17:40
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