I have a details table in my database that contains the number of rows.
See below. Divided into two rows, one column contains Rs 1250, 1250. I showed a total of 2500. But when the user wants to use the full total I want to update the data in two columns, how to update these two rows in laravel?
$wallet_details = tbl_wallet_detail::where('wd_parent_id', $usewallet->wm_id) ->whereMonth('tbl_wallet_details.wd_start_date', date('m')) ->whereYear('tbl_wallet_details.wd_start_date', date('Y'))->first(); $wallet_details->wd_used_amount = $wallet_details->wd_used_amount + $request->usewallet; $wallet_details->wd_remaining_amount = $wallet_details->wd_remaining_amount - $request->usewallet; $wallet_details->save();
I don't know all the details of your use case (e.g. how do you get the amount
user
has used), however, one way to solve your problem is outlined below.I created a
Wallet
model and associated table for this example and defined aused
column on it to represent the amount used, and similarremaining columns. Obviously, you can replace these with your specific information.
sum
(total)the
usedfield values for a given
user$remaining
amount by subtracting the amount used (in your example 1500) from the total amount obtained in step 1columns
for each row in the table for a givenuser
user_id
is just an example but you can use
transaction idor whatever makes sense for your use case .