I'm trying to make a simple function that will charge cashback for purchases on the site. The principle is as follows: I have a buy
table, where all purchase operations are indicated, and in this table there are 3 required columns: user_id
, bank
and status
. Bank - transaction amount, status - transaction status, user_id - ID at users
table. If status is 2
, then the purchase has been paid. I take all the data from the buy
table, get it with status = 2, and then I need to enter to the users
table, find the user ID there by user_id
from the buy
table, see the amount of his purchase where status is 2, and if everything is fine, I need to add 1 % cashback of the purchase amount.
I'm trying to do it all with this function:
public function cashbackUser()
{
$find_user = DB::table('buy')->where('status', 2)->get();
$users = DB::table('users')->get();
foreach ($users as $addCashback) {
$addCashback->cashback = $addCashback->cashback + $find_user->bank / 100 * 1;
$addCashback->save();
}
}
But i received error: Property [bank] does not exist on this collection instance.
. How i understand, it can't find the all summs from bank
at buy
table, because i can't to use ->get()
? What i need to change and get work it?