mysql - Laravel update based on other value -
how can translate used within laravel query builder ?
mysql
update mytable set val = val +1 id = 1
in laravel
$res = db::table('mytable') ->update(['val' => ?]);
thanks
try:
db::table('mytable')->where('id',1)->increment('val');
the increment
method accept second parameter amount sum, if need val = val + 2
can use ->increment('val', 2)
.
see reference: https://laravel.com/api/5.3/illuminate/database/eloquent/builder.html#method_increment
Comments
Post a Comment