o1; $odds['dc12'] = (float) $value->o2; $odds['dcx2'] = (float) $value->o3; } $odds['margin'] = (float) Margin::calculate([$odds['dc1x'], $odds['dc12'], $odds['dcx2']], 1); $res = OddsDc::where('event_id', $odds['event_id'])->where('bookmaker_id', $odds['bookmaker_id'])->first(); if (! $res) { OddsDc::create($odds); } elseif (! $block_update) { $res->dc1x = $odds['dc1x']; $res->dc12 = $odds['dc12']; $res->dcx2 = $odds['dcx2']; $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); } } }