A Laravel package to get IP addresses geographical location.
reefki/laravel-geoip is a Laravel package for a laravel package to get ip addresses geographical location..
It currently has 21 GitHub stars and 659 downloads on Packagist (latest version v2.0.0).
Install it with composer require reefki/laravel-geoip.
Discover more Laravel packages by reefki
or browse all Laravel packages to compare alternatives.
Last updated
A Laravel package to get geographical location information from IP addresses.
Install the package via Composer:
composer require reefki/laravel-geoip
Optionally, publish the config file:
php artisan vendor:publish --provider="Reefki\Geoip\GeoipServiceProvider" --tag="config"
use Reefki\Geoip\Geoip;
$geoip = Geoip::get('8.8.8.8');
$geoip->driver; // geojs
$geoip->ip; // 8.8.8.8
$geoip->city; // Mountain View
$geoip->region; // California
$geoip->country; // United States
$geoip->country_code; // US
$geoip->continent_code; // NA
$geoip->timezone; // America/Los_Angeles
$geoip->latitude; // 37.751
$geoip->longitude; // -97.822
$geoip->cached; // true or false
IPv6 addresses are also supported:
$geoip = Geoip::get('2001:4860:4860::8888');
By default, results are cached. To get realtime data:
Geoip::get('8.8.8.8', cache: false);
Get GeoIP data for the current request's IP address:
$geoip = $request->geoip();
With anonymized IP (for GDPR compliance):
$geoip = $request->geoip(anonymize: true);
Get just the anonymized IP address:
$anonymizedIp = $request->anonymizedIp();
// 8.8.8.8 → 8.8.8.0
// 2001:4860:4860::8888 → 2001:4860:4860::
Set the default driver in your .env file:
GEOIP_DEFAULT_DRIVER=geojs
Configure caching behavior:
GEOIP_CACHE_STORE=redis
GEOIP_CACHE_TTL=86400
Configure timeout and retry for API requests:
GEOIP_TIMEOUT=10
GEOIP_RETRY=3
GeoJS is a free service with no API key required.
Geoip::driver('geojs')->get('8.8.8.8');
IPData requires an API key. Register for an account and add your key to .env:
IPDATA_API_KEY=your_api_key
Then use the driver:
Geoip::driver('ip-data')->get('8.8.8.8');
Note: IPData offers 1,500 free requests per day. Higher usage requires a paid plan.
vendor/bin/phpunit
The MIT License (MIT). Please see License File for more information.