I have the following code:

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

$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! :)

推荐答案

create persists to the database while make just creates a new instance of the model.

The create method not only creates the model instances but also saves them to the database using Eloquent's save method

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

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

Laravel相关问答推荐

如何在 Laravel 中获取特定月份的最后一个日期?

我的共享主机上的每个帖子请求都出现 503 服务不可用

将数据从控制器传递到 Laravel 中的视图

如何在 Laravel Eloquent Collection 数组之前添加一个键值对?

laravel 关系集合上的自定义排序

Laravel - 排序的集合输出不是数组

有条件的Eager加载

Laravel 分页方法不适用于 map 集合?

如果值存在于另一个字段数组中,Laravel 验证规则

在Lumen框架中启用会话

Laravel 迁移命名约定

为什么 BroadCastEvent 在 Laravel 中排队?如何阻止它?

如何在laravel 5.1中使用url(路由)传递多个参数

Laravel Mix 生成字体到另一个目录

Laravel 的 toSql() 方法是否会屏蔽 id? (列值被问号替换)

如果 Laravel 中的值不为空,如何验证输入字段

改变模式生成器中的列长度?

Laravel 验证存在于不存在的地方

遍历 Laravel 控制器中的结果集

带有 Xdebug 的 Laravel 5 总是抛出The payload is invalid..