addDays($i)->toDateString(); $to = $date->addDays($i + 1)->toDateString(); $url = 'https://xml2.txodds.com/feed/result/xml.php?'.config('nuh.txodds_token_soccer')."&date=$from,$to&json=2"; $data = Curl::load($url); if ($print) { Notice::note($data, '', 1); } $count = 0; $e = []; foreach ($data['match'] as $match) { foreach ($match as $key => $v) { switch ($key) { case '@attributes': $e['txodds_id'] = (int) $v['id']; break; case 'time': $starttime = Carbon::createFromDate($v)->toDateTimeString(); break; case 'group': $e['sport_id'] = (int) $v['@attributes']['spid']; $e['country_id'] = (int) $v['@attributes']['cnid']; $e['group_id'] = (int) $v['@attributes']['id']; $e['competition_group_id'] = (int) $v['@attributes']['cgid']; Group::firstOrCreate([ 'txodds_id' => $v['@attributes']['id'], 'competition_group_id' => $e['competition_group_id'], ], [ 'name' => (string) $v['@text'], 'sport_id' => $e['sport_id'], 'country_id' => $e['country_id'], ]); CompetitionGroup::firstOrCreate([ 'txodds_id' => $v['@attributes']['cgid'], 'name' => $v['@attributes']['cname'], 'sport_id' => $e['sport_id'], 'country_id' => $e['country_id'], ]); break; case 'hteam': $e['home_id'] = $v['@attributes']['id']; Element::firstOrCreate([ 'txodds_id' => (int) $v['@attributes']['id'], 'name' => $v['@text'], 'sport_id' => $e['sport_id'], ]); break; case 'ateam': $e['away_id'] = $v['@attributes']['id']; Element::firstOrCreate([ 'txodds_id' => (int) $v['@attributes']['id'], 'name' => $v['@text'], 'sport_id' => $e['sport_id'], ]); break; } } Event::firstOrCreate($e, ['starttime' => $starttime]); $count++; } if ($debug) { Notice::note("$from - $count events processed", 'g'); } $total += $count; if ($break || $debug) { break; } } Notice::note("Total - $total events processed", 'g'); } }