Please how do i express this php mysql 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");
The ideal way to do this is to use the in-built Laravel function increment
$model = Some_Model::find( $id );
$model->increment('value',1000);
or
Some_Model::where('id',1)->increment('value',1000);
The documentation for the same is at http://laravel.com/docs/queries#raw-expressions
Using Eloquent you can write your queries as follow:
SomeTable::where('id', 1)
->update(array('value', DB::raw('value + 1000')));
You can just retrieve the model and increment it:
$model = Some_Model::find( $id );
$model->value += 1000;
$model->save();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With