我想为会员获得高级会员时创建一个函数,然后应调用此函数。这是我尝试过的代码:
public function updatePremium()
{
$comission = ChargeCommision::first();
$user = User::find(Auth::id());
$ref_id = $user->referrer_id;
$ref_user = User::find($ref_id);
$new = $ref_user['earning'] = $ref_user['earning'] + $comission->update_commision_sponsor;
$ref_user->save();
$new_balance = $user['balance'] = $user['balance'] - $comission['update_charge'];
$user['paid_status'] = 1;
$user->save();
Transaction::create([
'user_id' => $ref_user->id,
'trans_id' => rand(),
'time' => Carbon::now(),
'description' => 'REFERRAL COMMISSION'. '#ID'.'-'.'REF'.rand(),
'amount' => $comission->update_commision_sponsor,
'new_balance' => $new,
// need help here: I want to save a new column's value by the name of (new_earning)' => $new_earning,
'type' => 1,
'charge' => 0,
]);
Income::create([
'user_id' => $ref_user->id,
'amount' => $comission->update_commision_sponsor,
'description' => 'Deposit Commision From'.' '. $user->username,
'type' => 'R'
]);
// Taka to sponsor
updatePaid($user->id);
// UPDATE BV
updateDepositBV($user->id,'1');
Transaction::create([
'user_id' => $user->id,
'trans_id' => rand(),
'time' => Carbon::now(),
'description' => 'UPGRADE TO PREMIUM'. '#ID'.'-'.'UPDATE'.rand(),
'amount' => '-'.$comission['update_charge'],
'new_balance' => $new_balance,
//need help here: I want to save a new column's value by the name of (new_earning)' => $new_earning,
'type' => 2,
'charge' => 0,
]);
return redirect()->back()->with('message','Congratulations, You are successfully upgrade your account' );
}
我希望对其进行一些更改。就像我在“事务”表和“用户”表中添加了一个名为“ earning”和“ new_earning”的新列一样,现在我也希望将这两个列中的值也保存下来,同时保存其他列的值。但是我遇到了一些错误。
“用户”表的“收入”列正在保存值,但是“交易”表的new_earning列未保存值,并且在用户尝试升级其帐户时给我一个错误。
我尝试了许多替代方法来了解该错误。当我从“事务”表中删除“ new_earning”列(在更改时在表中添加了该列)时,该函数运行正常,并且用户没有错误。当我再次添加该列或在“事务”表中添加任何新列时,用户在升级帐户时会出错。
我不明白这是什么错误。将交易存储在“交易”表中是最重要的。
很抱歉,很长的文字,但我想完整地讨论一下,以便您可以理解我到底想说什么。谢谢。