laravel 用模型更新表全部数据写法

我想用模型更新一个表的全部数据,但是必须加个where条件才可以更新, 直接去掉where就会报错Non-static method Illuminate\Database\Eloquent\Model::update() should not be called statically, assuming $this from incompatible context。加这个where看着又别扭,且没啥实际意义,代码如下:

Goods::where(DB::raw(1), 1)->update([
    'start_time' => $start_time
]);

能去掉这个where嘛?
试过用 (new Goods)->update(['start_time' => $start_time]),但是实际没任何sql执行, 也不想用DB::table('goods')->update()这种更新方式~.

阅读 7.3k
1 个回答

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

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题