Laravel 文档中 Eloquent: 入门 部分翻译 的疑问 ?

快速入门《Laravel 5.4 中文文档》

{note} 当通过“Eloquent”批量更新时,saved和updated模型事件将不会被更新后的模型代替。这是因为批量更新时,模型从来没有被取回

关于上边的说法,不是很理解,谁能解释一下?

jaak
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
讨论数量: 1
App\Flight::where('active', 1)
          ->where('destination', 'San Diego')
          ->update(['delayed' => 1]);

此处 update() 方法属于类 Illuminate\Database\Eloquent\Builder,进一步调用 Illuminate\Database\Query\Builder:

/**
     * Update a record in the database.
     *
     * @param  array  $values
     * @return int
     */
    public function update(array $values)
    {
        $sql = $this->grammar->compileUpdate($this, $values);

        return $this->connection->update($sql, $this->cleanBindings(
            $this->grammar->prepareBindingsForUpdate($this->bindings, $values)
        ));
    }

file
Laravel 文档在模型快速入门中指明 Eloquent 模型是查询构造器,当通过模型进行批量操作的时候,是通过查询构造器操作的。模型事件触发是针对某个特定的模型的,即是通过类 Illuminate\Database\Eloquent\Model 的方法操作的。

5年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!