我有以下代码:
$this->actingAs(factory('App\User')->create());
$thread = factory('App\Thread')->make();
create()和make()有什么区别?为什么它没有列在Laravel文档的帮助函数页面中?谢谢! :)
答案 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.