Skip to content

Commit

Permalink
Merge pull request #68 from ip2location/master
Browse files Browse the repository at this point in the history
added ip2locationio service to geo middleware
  • Loading branch information
denisdulici authored Sep 25, 2023
2 parents 9529b10 + fd996f0 commit 6291290
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Config/firewall.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
'block' => [], // i.e. 'London'
],

// ipapi, extremeiplookup, ipstack, ipdata, ipinfo, ipregistry
// ipapi, extremeiplookup, ipstack, ipdata, ipinfo, ipregistry, ip2locationio
'service' => 'ipapi',

'auto_block' => [
Expand Down
24 changes: 24 additions & 0 deletions src/Middleware/Geo.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,30 @@ public function ipregistry($location)
return $location;
}

public function ip2locationio($location)
{
$url = 'https://api.ip2location.io/?ip=' . $this->ip() . '&key=' . env('IP2LOCATIONIO_KEY');

$response = $this->getResponse($url);

if (! is_object($response) || empty($response->location)) {
return false;
}

$location->country = $response->country_name;
$location->country_code = $response->country_code;
$location->region = $response->region_name;
$location->city = $response->city_name;
$location->latitude = $response->latitude;
$location->longitude = $response->longitude;
$location->zipcode = $response->zip_code;
$location->timezone = $response->time_zone;
$location->asn = $response->asn;
$location->as = $response->as;

return $location;
}

protected function getResponse($url)
{
try {
Expand Down

0 comments on commit 6291290

Please sign in to comment.