我有以下代码:
$this->actingAs(factory('App\User')->create());
$thread = factory('App\Thread')->make();
create()和make()之间有什么区别,为什么在Laravel文档的帮助器功能页面中未列出?谢谢!:)
create
在make
刚创建模型的新实例时将持久化到数据库。
该
create
方法不仅创建模型实例,而且使用Eloquent的save方法将其保存到数据库中
https://laravel.com/docs/5.4/database-testing#using-factories
如果您想查看make和create之间的源代码差异,可以在 src/Illuminate/Database/Eloquent/FactoryBuilder.php
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句