【问题标题】:Laravel Faker - What's the difference between create and makeLaravel Faker - create 和 make 有什么区别
【发布时间】:2017-10-22 11:55:53
【问题描述】:

我有以下代码:

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

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

create() 和 make() 有什么区别,为什么 Laravel 文档的帮助函数页面中没有列出?谢谢! :)

【问题讨论】:

    标签: php laravel faker


    【解决方案1】:

    create 持久化到数据库中,而make 只是创建模型的一个新实例。

    create 方法不仅可以创建模型实例,还可以保存 使用 Eloquent 的保存方法将它们保存到数据库中

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

    如果您想查看 make 和 create 之间的源代码差异,可以在 src/Illuminate/Database/Eloquent/FactoryBuilder.php 中查看它们

    【讨论】:

      【解决方案2】:
      Laravel create method is created the model instance and save data in the database.
      Make function has created the instance of the class.
      

      click here for more info

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-10-20
        • 2010-11-14
        • 1970-01-01
        • 1970-01-01
        • 2019-07-03
        相关资源
        最近更新 更多