Laravel模型更新全表如何实现?

Song1087 次浏览0个评论2024年03月11日

在使用Laravel模型更新一个表的全部数据,但是必须加个where条件才可以更新, 直接去掉where就会报错

Non-static method Illuminate\Database\Eloquent\Model::update() should not be called statically, assuming $this from incompatible context。

加这个where看着又别扭,且没啥实际意义,代码如下:

Goods::where("id",">",0)->update([ 'start_time' => $start_time ]);

那么如何去掉呢?并且实现功能呢:

Goods::query()->update([]);


更多相关好文