Simon Suh Simon Suh - 1 year ago 41
PHP Question

In Laravel, what's the difference between ->create() and ->make()

I have the following code:

$this->actingAs(factory('App\User')->create());

$thread = factory('App\Thread')->make();


what is the difference between create() and make() and why is it not listed in the helper functions page in the Laravel documentation? Thank you! :)

Answer Source

create persists to the database while make just news up the model.

The create method not only creates the model instances but also saves them to the database using Eloquent's save method

https://laravel.com/docs/5.4/database-testing#using-factories

If you'd like to see the code differences between make and create you can see them in src/Illuminate/Database/Eloquent/FactoryBuilder.php

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download