football('/odds/live'); foreach ($list['response'] as $item) { $sport = Sport::where('data_id', $item['fixture']['id'])->first(); $sport->odds = json_encode($item['odds']); $sport->save(); } return $this->success($list); } function football($api, $params = []) { $url = config('services.api_football.host'); $url .= $api; $url .= "?" . http_build_query($params); $key = config('services.api_football.key'); $options = [ 'http' => [ 'method' => 'GET', 'header' => "x-rapidapi-key: {$key}" ] ]; $context = stream_context_create($options); $response = file_get_contents($url, false, $context); if ($response === FALSE) { die('Error occurred while fetching data'); } return json_decode($response, true); } }