【问题标题】:Laravel 7.x: Difference between fresh and refresh method?Laravel 7.x:新鲜和刷新方法之间的区别?
【发布时间】:2021-01-03 06:04:33
【问题描述】:

在阅读 Laravel 文档时,我在 Eloquent 模型上遇到了一个名为 freshrefresh 的方法。请解释它们之间的主要区别?我很难理解这些。

【问题讨论】:

    标签: laravel eloquent laravel-7 eloquent-relationship


    【解决方案1】:

    这是refresh 方法在Illuminate\Database\Eloquent\Model 上的注释:

    /**
     * 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 将从数据库中获取模型的新实例并返回。

    【讨论】:

      猜你喜欢
      • 2018-01-16
      • 2020-11-14
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 2012-01-25
      • 2010-12-05
      • 2015-10-21
      • 1970-01-01
      相关资源
      最近更新 更多