I am using Laravel and I have the following problem. When executing a function on my play site, I need to update different values, but in the same table column.
I will give an example: there is a team A and a team B. When a user places a bet on team A, everything is fine, when a user places a bet on team B, everything is also fine, already the third user places a bet on any of the teams, the coefficient of all bets of that team is updated, on which the user made a bet.
For example: On team A the bet is $ 1, the coefficient for the team is recorded as x1, and on the opposite coefficient it becomes x2. Further, if the user places a $ 7.62 bet on team B, the odds are recorded as x1.13. And if the third user places a $ 2 bet on team A, then all odds with a bet on team A change to x3.19, this is how it should be. But the bet on team B in the base is displayed as the old value x1.13, although the odds should change.
That is, how i understand, for any bet on an event where match_id
is the same, i need to change the coefficients for all bets after the next bet. How can I do this correctly?
My code, which changes all X bets where the team ID matches:
if ($betsCount > 1) {
$matchUsers = Bets_match::where('team_id', $request->teamID)->get();
foreach ($matchUsers as $matchUser) {
$x = $tournamentMatch->team1_id == $matchUser->team_id ? $tournamentMatch->x1 : $tournamentMatch->x2;
$coef_percent = $x * self::COMMISSION_PERCENT / 100;
$x = $x - $coef_percent;
$matchUser->x = $x;
$matchUser->save();
}
}
question from:
https://stackoverflow.com/questions/65947484/how-to-properly-update-multiple-values-in-a-table 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…