Skip to content

Commit de95ca2

Browse files
committed
Fix error with hydrating data from IPData
1 parent 948617d commit de95ca2

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/Services/IPData.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Torann\GeoIP\Services;
44

55
use Exception;
6+
use Illuminate\Support\Arr;
67
use Torann\GeoIP\Support\HttpClient;
78

89
/**
@@ -47,6 +48,21 @@ public function locate($ip)
4748
throw new Exception('Request failed (' . $this->client->getErrors() . ')');
4849
}
4950

50-
return $this->hydrate(json_decode($data[0], true));
51+
$json = json_decode($data[0], true);
52+
53+
return $this->hydrate([
54+
'ip' => $ip,
55+
'iso_code' => $json['country_code'],
56+
'country' => $json['continent_name'],
57+
'city' => $json['city'],
58+
'state' => $json['region_code'],
59+
'state_name' => $json['region'],
60+
'postal_code' => $json['postal'],
61+
'lat' => $json['latitude'],
62+
'lon' => $json['longitude'],
63+
'timezone' => Arr::get($json, 'time_zone.name'),
64+
'continent' => Arr::get($json, 'continent_code'),
65+
'currency' => Arr::get($json, 'currency.code'),
66+
]);
5167
}
5268
}

0 commit comments

Comments
 (0)