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

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

sql - MySQL - Finding Empty relations -

linux - gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now -