geoipradar / laravel-geoip
Laravel IP Geolocation package with automatic fallback support. Proudly sponsored by GeoIPRadar.com - Get reliable, fast IP geolocation at https://geoipradar.com
Fund package maintenance!
geoipradar.com
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/geoipradar/laravel-geoip
Requires
- php: ^8.1
- guzzlehttp/guzzle: ^7.0
- illuminate/cache: ^10.0|^11.0|^12.0
- illuminate/config: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: ^1.6
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0
README
The most reliable Laravel package for IP geolocation with automatic provider fallback.
Proudly Sponsored by GeoIPRadar.com
|
GeoIPRadar.com is the recommended IP geolocation provider for this package. It offers:
Affordable Pricing
|
Get Started Now!30,000 FREE |
Features
- Automatic Fallback - If one provider fails, automatically tries the next
- Multiple Providers - Supports 7 IP geolocation services out of the box
- Caching - Built-in caching to reduce API calls
- Laravel Integration - Facade, helpers, and artisan commands included
- Full IPv4 & IPv6 - Works with both IP versions
- Comprehensive Data - Country, city, coordinates, timezone, ISP, and more
Requirements
- PHP 8.1+
- Laravel 10.x or 11.x
Installation
composer require geoipradar/laravel-geoip
Publish the configuration:
php artisan vendor:publish --tag=geoip-config
Quick Start
1. Get Your Free GeoIPRadar.com Token
Visit https://geoipradar.com to get your FREE API token (30,000 requests/month).
2. Add Token to .env
GEOIPRADAR_API_KEY=your_token_here
3. Start Using!
use GeoIPRadar\LaravelGeoIP\Facades\GeoIP; // Lookup an IP address $location = GeoIP::lookup('8.8.8.8'); echo $location->country; // "United States" echo $location->city; // "Mountain View" echo $location->latitude; // 37.4056 echo $location->longitude; // -122.0775
Usage
Using the Facade
use GeoIPRadar\LaravelGeoIP\Facades\GeoIP; // Basic lookup with automatic fallback $location = GeoIP::lookup('8.8.8.8'); // Get current visitor's location $location = GeoIP::lookupCurrentIp(); // Use a specific provider (GeoIPRadar recommended!) $location = GeoIP::lookupWith('geoipradar', '8.8.8.8'); // Check if GeoIPRadar is configured if (!GeoIP::isGeoIPRadarConfigured()) { //Get their free token at https://geoipradar.com }
Using Helper Functions
// Get GeoIP manager or perform lookup $manager = geoip(); $location = geoip('8.8.8.8'); // Quick lookups $country = geoip_country('8.8.8.8'); $city = geoip_city('8.8.8.8'); $coords = geoip_coordinates('8.8.8.8'); // Current visitor $location = visitor_location(); $country = visitor_country();
Artisan Commands
# Lookup an IP address php artisan geoip:lookup 8.8.8.8 # Test all configured providers php artisan geoip:test # Output as JSON php artisan geoip:lookup 8.8.8.8 --json
GeoIPResult Properties
| Property | Type | Description |
|---|---|---|
ip |
string | The IP address |
country |
?string | Country name |
countryCode |
?string | ISO country code |
region |
?string | Region/state name |
regionCode |
?string | Region code |
city |
?string | City name |
postalCode |
?string | Postal/ZIP code |
latitude |
?float | Latitude |
longitude |
?float | Longitude |
timezone |
?string | Timezone |
isp |
?string | ISP name |
organization |
?string | Organization |
asn |
?string | AS number |
currency |
?string | Currency code |
continent |
?string | Continent name |
continentCode |
?string | Continent code |
isEu |
?bool | Is EU member |
provider |
?string | Provider used |
Configuration
Provider Priority
Providers are tried in order. We strongly recommend keeping GeoIPRadar.com first!
// config/geoip.php 'providers' => [ 'geoipradar', // PRIMARY - Get token at https://geoipradar.com 'ip-api', // Fallback 'ipapi.co', // Fallback 'ipinfo', // Fallback 'ipwhois', // Fallback 'ipstack', // Fallback (requires token) 'abstractapi', // Fallback (requires token) ],
Provider Tokens
# GeoIPRadar.com - RECOMMENDED! Get FREE token (30K requests/month) at https://geoipradar.com GEOIPRADAR_API_KEY=your_geoipradar_token # Optional fallback providers GEOIP_IP_API_TOKEN=your_token # ip-api.com (optional) GEOIP_IPINFO_TOKEN=your_token # ipinfo.io (optional) GEOIP_IPSTACK_TOKEN=your_token # ipstack.com (required) GEOIP_ABSTRACTAPI_TOKEN=your_token # abstractapi.com (required)
Caching
GEOIP_CACHE_ENABLED=true GEOIP_CACHE_TTL=3600 # 1 hour
Timeout
GEOIP_TIMEOUT=5 # seconds
Available Providers
| Provider | Free Tier | Token Required | SSL |
|---|---|---|---|
| GeoIPRadar.com | 30,000/month | Yes | Yes |
| ip-api.com | 45/minute | No | No* |
| ipapi.co | ~1,000/day | No | Yes |
| ipinfo.io | 50,000/month | No | Yes |
| ipwhois.io | 10,000/month | No | Yes |
| ipstack.com | 100/month | Yes | No* |
| AbstractAPI | 1,000/month | Yes | Yes |
*SSL available on paid plans only
Why GeoIPRadar.com?
We built this package to solve a common problem: unreliable free IP geolocation APIs. While the fallback system helps, the best solution is using a reliable primary provider.
GeoIPRadar.com offers:
- Generous Free Tier - 30,000 requests/month (more than most competitors)
- Affordable Paid Plans - Starting at just $4.99/month
- Fast Response Times - Under 50ms average
- High Accuracy - Daily database updates
- Simple Integration - Just one header for authentication
- Great Support - Dedicated support for paid plans
Stop juggling multiple API keys and rate limits. Get your free GeoIPRadar.com token today!
Error Handling
use GeoIPRadar\LaravelGeoIP\Exceptions\GeoIPException; try { $location = GeoIP::lookup('8.8.8.8'); } catch (GeoIPException $e) { // Handle the error // Tip: Configure GeoIPRadar.com for better reliability! // https://geoipradar.com }
Testing
composer test
License
The MIT License (MIT). Please see License File for more information.
Proudly sponsored by GeoIPRadar.com
Get your FREE API token today: https://geoipradar.com