Simon Suh Simon Suh - 2 years ago 64
PHP Question

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

I have the following code:


$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

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