$store_obj = new account;
$x = \Auth::user()->id
$old = account::where('id',$x)->first();
echo $old->wallet;
$new = Input::get("update");
echo $new;
$upd = sum($old,$new);// strucked here
echo $upd;
Asked
Active
Viewed 3,562 times
-2

Vinod VT
- 6,946
- 11
- 51
- 75

Jeevan R Sharma
- 3
- 1
- 2
-
$old is an array ? – Vinod VT Jul 15 '16 at 12:08
-
try this one will work `echo $old->wallet + $new;` – Sagar Naliyapara Jul 15 '16 at 12:09
-
$old is an Object, where as $new is a variable! Maybe indeed, you want something like the upper answer. `echo $old->wallet + $new;` – klodoma Jul 15 '16 at 12:10
-
To know what exact type of data is inside `$old` and `$new` you need to use `var_dump` instead using `echo`. Maybe you need to do `$upd = sum($old->wallet, $new);`, too. – OscarGarcia Jul 15 '16 at 12:10
-
If `sum` wasn't defined, `sum` function doesn't exists. Are you trying to add two numeric values? Use `$upd = $old->wallet + $new;`. Are you trying to add the property to a existent class? Use `$old->new = $new;` (for example). Updating the property? Use `$old->wallet = $new;`. – OscarGarcia Jul 15 '16 at 12:25
1 Answers
0
I couldn't find sum
function in Laravel helper docs. AFAIK, sum
is one of aggregate method of query builder. I don't get on what you're trying to achieve, but I'll just assume you're going to update the model with adding those model value with given input value.
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\account;
use Auth;
use App\Http\Requests;
class YourController extends Controller
{
public function update(Request $request)
{
$update = $request->input('update');
$id = Auth::user()->id;
$account = account::where('id', $x);
$account->increment('wallet', $update); //<---
$updated = $account->first();
return $updated;
}
}
I don't recommend the usage of native PHP echo
, print_r
or var_dump
for debugging purpose. Use built-in Laravel dump
or dd
instead.
Of course, from code above, you need to validate user input before storing to DB.

Chay22
- 2,834
- 2
- 17
- 25