1

I have this:

private function logSearch($term)
    {
        $geo_data = $this->geoIP($ip);
        dd($geo_data);
    }

public function geoIP($ip)
    {
        $url = "http://api.ipstack.com/$ip?access_key=" . env('GEOIP_KEY');    
        $response = $this->client->request('GET', $url);
        return $response->getBody();
    }

The response should be:

{"ip":"78.63.56.237","type":"ipv4","continent_code":"EU"...etc}

But instead I am getting:

Stream {#482
  -stream: stream resource @290
    wrapper_type: "PHP"
    stream_type: "TEMP"
    mode: "w+b"
    unread_bytes: 0
    seekable: true
    uri: "php://temp"
    options: []
  }
  -size: null
  -seekable: true
  -readable: true
  -writable: true
  -uri: "php://temp"
  -customMetadata: []
}
imperium2335
  • 23,402
  • 38
  • 111
  • 190

1 Answers1

0

I think you need to add getContents().
This answer would be useful for you: Guzzlehttp - How get the body of a response from Guzzle 6?
Please try this code.

private function logSearch($term)
{
    $geo_data = $this->geoIP($ip);
    dd($geo_data);
}

public function geoIP($ip)
{
    $url = "http://api.ipstack.com/$ip?access_key=" . env('GEOIP_KEY');    
    $response = $this->client->request('GET', $url);
    return $response->getBody()->getContents();
}
kuromoka
  • 832
  • 7
  • 13