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

Song201 次浏览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([]);


提交评论

请登录后评论

用户评论

    当前暂无评价,快来发表您的观点吧...

更多相关好文