为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
摇曳的蔷薇 2019-03-12 05:16:25
我想用模型更新一个表的全部数据,但是必须加个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()这种更新方式~.
查看完整描述

2 回答

?
守着一只汪

TA贡献1872条经验 获得超3个赞

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

查看完整回答
反对 回复 2019-03-18
  • 2 回答
  • 0 关注
  • 865 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信