How can I express this mysql php update code in eloquent
mysql_query("UPDATE `some_table` SET `value` = `value` + 1000 WHERE `id` = 1");
or
mysql_query("UPDATE `some_table` SET `value` = `value` + $formdata WHERE `id` = 1");
You can just get the model and enlarge it:
$model = Some_Model::find( $id ); $model->value += 1000; $model->save();
The ideal way to do this is to use the built-in Laravel increment function
increment
$model = Some_Model::find( $id ); $model->increment('value',1000);
Some_Model::where('id',1)->increment('value',1000);
The documentation at the same address is at http://laravel.com/docs/queries#raw-expressions
Using Eloquent, you can write your queries as follows:
SomeTable::where('id', 1) ->update(array('value', DB::raw('value + 1000')));
Source: https://habr.com/ru/post/1496693/More articles:How to increase the productivity of the next cycle - performanceGoogle search bar on website - javascriptHow does AngularJS update the DOM? - javascripthtaccess from www to non-www casting a variable to session / cookie - redirectHow to determine if TypeElement indirectly implements an interface - javaHow to add assembly step for leiningen? - clojureUnique sort order for pagination by postgres - sqlJava - Duplicate methods in classes and how to call them from another class - javaAndroid onCreate Called Twice action when navigating from another action - androidLocation http.sys? - iisAll Articles