D
D
DenKG2016-12-04 20:15:12
Laravel
DenKG, 2016-12-04 20:15:12

How to sum up the incoming data with the data already available in the database?

In my form I have something like this:

<input type="hidden" name="purse_balance" id="Purse-purse_balance" class="form-control">

In the controller like this:
public function trans(Request $request){
   $balance = new Purse;
   $transactions = new Transaction;

   $transactions->trans_pay_sum = $request->trans_pay_sum;
   $transactions->trans_pay_appoint = $request->trans_pay_appoint;
   $transactions->trans_pay_purse_name = $request->trans_pay_purse_name;
   $transactions->trans_pay_purse_client_id = Auth::id();
   $balance->purse_balance = $request->purse_balance;
   if($request->get('page') == 'moneyfill')
{
   $this->purse($request);
 }
}

public function purse(Request $request){
     $purse = new Purse;
     $balance = new Purse;
     $purse = Purse::where('purse_name', $request->trans_pay_purse_name)->first();
     $balance = $request->purse_balance;
     $result= $request->trans_pay_sum;
     $balance=$result+$balance;
     $purse->purse_balance = $balance;
     $purse->save();
     return view('home');
  }

I need the incoming amount to be trans_pay_sumadded to the amount already available purse_balance.
But my code makes it so that the incoming amount of money is simply overwritten in the balance, which is not added to the amount already on the account.
I would be grateful for help in this matter)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Aksentiev, 2016-12-04
@DenKG

$purse->increment('purse_balanse',  $request->trans_pay_sum);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question