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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macroable to FactoryBuilder class #19425

merged 1 commit into from May 31, 2017


None yet
2 participants

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

1 of 2 checks passed

continuous-integration/styleci/pr The StyleCI analysis has errored
continuous-integration/travis-ci/pr The Travis CI build passed

@jerguslejko jerguslejko deleted the jerguslejko:factory-builder branch May 31, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment