Laravel Faker - 创造和制造之间的区别

时间:2017-05-22 18:07:57

标签: php laravel faker

我有以下代码:

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

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

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

2 个答案:

答案 0 :(得分:19)

create持久存储到数据库,而make只创建模型的新实例。

  

create方法不仅可以创建模型实例,还可以保存   使用Eloquent的保存方法

将它们添加到数据库中

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

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

中看到它们

答案 1 :(得分:1)

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