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

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -