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

[5.4] Add raw method to FactoryBuilder #17734

Merged
merged 1 commit into from
Feb 2, 2017
Merged

[5.4] Add raw method to FactoryBuilder #17734

merged 1 commit into from
Feb 2, 2017

Conversation

jerguslejko
Copy link
Contributor

@jerguslejko jerguslejko commented Feb 2, 2017

This PR adds raw() method to Illuminate\Database\Eloquent\FactoryBuilder.

It allows for calling factory(User::class)->raw() which returns raw attributes array (merged with overrides). raw() method behaves in a same way as make() or create() methods do.

It aligns nicely with Illuminate\Database\Eloquent\Factory::raw() method which is available inside factories.

This feature is useful when writing tests for a simple endpoint:

function it_creates_an_order()
{
    $request = factory(App\Order::class)->make()->toArray();

    // vs

    $request = factory(App\Order::class)->raw();

    $this->post('/orders', $request);
}

Also, it could be used with hasMany relationships:

$post->comments()->create(
    factory(App\Comment::class, 3)->raw()
);

🌵

@taylorotwell taylorotwell merged commit a0ed1d4 into laravel:5.4 Feb 2, 2017
@jerguslejko jerguslejko deleted the feature/factory-raw branch February 2, 2017 19:48
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