Laravel 7.x:fresh方法和refresh方法有什么区别?

15

我在阅读 Laravel 文档时遇到了 Eloquent 模型中的 freshrefresh 方法,请解释一下它们之间的主要区别。我很难理解它们。

2个回答

17

这是对Illuminate\Database\Eloquent\Modelrefresh方法的评论:

/**
 * Reload the current model instance with fresh attributes from the database.
 *
 * @return $this
 */
public function refresh()

这里是“fresh”这个词的翻译:

/**
 * Reload a fresh model instance from the database.
 *
 * @param  array|string  $with
 * @return static|null
 */
public function fresh($with = [])

refresh将刷新当前模型实例(包括关联)。fresh会从数据库中获取一个新的模型实例并返回它。


-3

enter image description here

RefreshCommand

重置并重新运行所有迁移


新命令

删除所有表并重新运行所有迁移


2
问题涉及到Eloquent方法,而不是迁移。 - roerjo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接