backtheweb/laravel-geoip
最新稳定版本:v0.0.1
Composer 安装命令:
composer require backtheweb/laravel-geoip
包简介
Laravel MaxMind GeoIp
README 文档
README
Available services
- MaxMind from $0.0001 per query
- Hacker Target Free with limited requests per day
- Ipinfo.io Free plan is limited to 50k requests per month
Installation
composer require backtheweb/laravel-geoip
php artisan vendor:publish --provider="Backtheweb\GeoIp\GeoIpServiceProvider" --tag="config"
Edit geoip.php in config folder or ser environment vars.
return [
'default' => env('GEO_IP_SERVICE', 'maxmind'),
'services' => [
'maxmind' => [
'user' => env('GEO_IP_MAXMIND_USER_ID'),
'key' => env('GEO_IP_MAXMIND_LICENSE_KEY'),
'database' => env('GEO_IP_MAXMIND_DATABASE', 'country'),
],
'hackertarget' => [],
'ipinfoio' => [
'token' => env('GEO_IP_IPINFOIO_TOKEN'),
],
],
'test' => [
'ip' => env('GEO_IP_TEST_IP'),
'city' => env('GEO_IP_TEST_CITY'),
'country' => env('GEO_IP_TEST_COUNTRY'),
]
];
Usage
use Backtheweb\GeoIp\Facades\GeoIp
$location = GeoIp::location('172.105.90.46');
$location->toArray();
Sample output of $location->toArray()
array [
"ip" => "172.105.90.46"
"hostname" => null
"country" => "Germany"
"country_code" => "DE"
"state" => "Hesse"
"city" => "Frankfurt am Main"
"postal_code" => "60313"
"lat" => 50.1188
"lng" => 8.6843
"timezone" => "Europe/Berlin"
"provider" => "Linode"
]
Available response properties
| MaxMind** | Hacker Target | IpInfo.io | |
|---|---|---|---|
| ip | ✓ | ✓ | ✓ |
| hostname | ✓ | ||
| country | ✓ | ✓ | ✓ |
| country_code | ✓ | ✓ | ✓ |
| postal_code | ✓ | ✓ | ✓ |
| lat | ✓ | ✓ | ✓ |
| lng | ✓ | ✓ | ✓ |
| timezone | ✓ | ✓ | |
| provider | ✓ | ✓ |
** Unsing insights database
Testing
create a .env file with the following content
GEO_IP_TEST_IP=172.105.90.46
GEO_IP_TEST_CITY="Hesse"
GEO_IP_TEST_COUNTRY=Germany
and run
composer test
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-02-22