o1; $odds['a2w'] = (float) $value->o3; } $odds['margin'] = (float) Margin::calculate([$odds['h2w'], $odds['a2w']], 1); $res = Odds2way::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first(); if (! $res) { Odds2way::create($odds); } elseif (! $block_update) { $res->h2w = $odds['h2w']; $res->a2w = $odds['a2w']; $res->flags = 1; $res->margin = $odds['margin']; $max_tries = 5; $tries = 0; do { $retry = false; try { $res->save(); return $res; } catch (PDOException $exc) { if ($tries < $max_tries && $exc->errorInfo[0] == 40001 && $exc->errorInfo[1] == 1213) { $retry = true; sleep(1); } else { throw $exc; } } } while ($retry); } } }