Skip to content

Commit 2ffec7d

Browse files
committed
added ipregistry service to geo middleware
1 parent fc67f04 commit 2ffec7d

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Config/firewall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
'block' => [], // i.e. 'London'
173173
],
174174

175-
// ipapi, extremeiplookup, ipstack, ipdata, ipinfo
175+
// ipapi, extremeiplookup, ipstack, ipdata, ipinfo, ipregistry
176176
'service' => 'ipapi',
177177

178178
'auto_block' => [

src/Middleware/Geo.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,33 @@ protected function ipinfo($location)
155155
return $location;
156156
}
157157

158+
public function ipregistry($location)
159+
{
160+
$url = 'https://api.ipregistry.co/' . $this->ip() . '?key=' . env('IPREGISTRY_KEY');
161+
162+
$response = $this->getResponse($url);
163+
164+
if (! is_object($response) || empty($response->location)) {
165+
return false;
166+
}
167+
168+
$location->continent = $response->location->continent->name;
169+
$location->country = $response->location->country->name;
170+
$location->country_code = $response->location->country->code;
171+
$location->region = $response->location->region->name;
172+
$location->city = $response->location->city;
173+
$location->timezone = $response->time_zone->id;
174+
$location->currency_code = $response->currency->code;
175+
176+
$location->is_eu = $response->location->in_eu;
177+
178+
if (! empty($response->location->language->code)) {
179+
$location->language_code = $response->location->language->code . '-' . $response->location->country->code;
180+
}
181+
182+
return $location;
183+
}
184+
158185
protected function getResponse($url)
159186
{
160187
try {

0 commit comments

Comments
 (0)