我想用where子句更新一行。 我没有行ID,只有我有2 where子句。 这可能吗? (与口才)laravel 5.1:我怎样才能用where子句更新一行?
->where("x",1) ->where("y"=2)
我想用where子句更新一行。 我没有行ID,只有我有2 where子句。 这可能吗? (与口才)laravel 5.1:我怎样才能用where子句更新一行?
->where("x",1) ->where("y"=2)
当使用Active Record时,不应该直接在数据库中执行更新。首先拉从数据库中的记录,然后更新它:
Model::where(['x' => 1, 'y' => 2])->first()->update([...]);
如果改为直接做更新的数据库,没有任何的ORM的功能会触发(如点火事件或感人的父母)。
更新所有的行,其对应的条件:
Model::where("x",1)->where("y",2)->update(array('key' => 'new_value', ...));
第一行,其对应的条件:
Model::where("x",1)->where("y",2)->first()->update(array('key' => 'new_value', ...));
当然,只是读取该行,然后更新像往常一样。
SomeModel::where('somecondition', 'somevalue')
->where('someothercondition', 'someothervalue')
->first()
->update(['somecolumn' => 'somenewvalue']);