interaction-design-foundation / laravel-geoip
Support for multiple Geographical Location services.
Package info
github.com/InteractionDesignFoundation/laravel-geoip
pkg:composer/interaction-design-foundation/laravel-geoip
Requires
- php: ^8.2
- ext-curl: *
- illuminate/cache: ^12.0 || ^13.0
- illuminate/console: ^12.0 || ^13.0
- illuminate/support: ^12.0 || ^13.0
- league/iso3166: ^4.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.50
- geoip2/geoip2: ^3.0
- orchestra/testbench: ^10.0 || ^11.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.0 || ^12.0
- rector/rector: ^2.0
- squizlabs/php_codesniffer: ^3.9 || ^4.0
- vimeo/psalm: ^6.0
Suggests
- geoip2/geoip2: Required to use the MaxMind database or web service with GeoIP (~2.1).
- dev-main
- 4.1.0
- 4.0.0
- 4.0.0-rc1
- 3.x-dev
- 3.7.4
- 3.7.3
- 3.7.2
- 3.7.1
- 3.7.0
- 3.6.0
- 3.5.2
- 3.5.1
- 3.5.0
- 3.4.6
- 3.4.5
- 3.4.4
- 3.4.3
- 3.4.2
- 3.4.1
- 3.4.0
- 3.3.0
- 3.2.2
- 3.2.1
- 3.2.0
- 3.1.2
- 3.1.1
- 3.1.0
- 3.0.2
- 3.0.1
- 1.2.1
- 1.2.0
- 1.1.1
- 1.1.0
- 1.0.13
- 1.0.12
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.8
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- 0.2.5
- 0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
- dev-update-coding-standard
- dev-l13
- dev-fix-psalm-types
- dev-contributors-readme-action-SMef7d77FE
- dev-contributors-readme-action-NQ_waorcJB
- dev-contributors-readme-action-vxl2zbPo68
- dev-contributors-readme-action-_8e_cE4qKC
- dev-contributors-readme-action-QAKBm99puD
- dev-contributors-readme-action-I_BNgsgn6t
- dev-contributors-readme-action-FblmTvp2bA
- dev-contributors-readme-action-L9EUfIUAVS
- dev-contributors-readme-action-n4LZD7Vge0
- dev-fix/maxmind-unchecked-io
- dev-refactor/immutable-location
- dev-fix/use-laravel-logger
- dev-contributors-readme-action-epI7NV5yNl
- dev-fix/ip2location-api-error-handling
- dev-fix/shouldCache-match-expression
- dev-worktree-fix-continent-lookup
- dev-contributors-readme-action-EsRkEBNitb
- dev-fix/service-instantiation-type-safety
- dev-contributors-readme-action-ZURrXifZT6
- dev-worktree-add-ip2location-service
- dev-worktree-replace-currencies-with-league-iso3166
- dev-fix/security-ssl-and-ip-spoofing
- dev-drop-laravel-10-11
- dev-defaultLocationResolver
This package is auto-updated.
Last update: 2026-03-06 13:11:58 UTC
README
Determine the geographical location and currency of website visitors based on their IP addresses.
Actively maintained fork of
torann/geoipwith modern PHP/Laravel support, better types, and additional features. Migration guide.
Installation
composer require interaction-design-foundation/laravel-geoip
Publish the config file:
php artisan vendor:publish --provider="InteractionDesignFoundation\GeoIP\GeoIPServiceProvider" --tag=config
Set the GEOIP_SERVICE env variable to one of the supported services.
Quick Start
Use the geoip() helper or the GeoIP facade:
// Get location for an IP $location = geoip('203.0.113.1'); // Get location for the current visitor $location = geoip()->getLocation(); // Access location data $location->city; // "New Haven" $location->country; // "United States" $location->iso_code; // "US" $location->timezone; // "America/New_York" $location->currency; // "USD"
The Location object contains: ip, iso_code, country, city, state, state_name, postal_code, lat, lon, timezone, continent, currency, default, and cached.
It implements ArrayAccess, so both $location->city and $location['city'] work.
Services
Set the service via the GEOIP_SERVICE env variable or in config/geoip.php:
| Service | Key | Requires |
|---|---|---|
| MaxMind Database | maxmind_database |
geoip2/geoip2 package + license key |
| MaxMind Web API | maxmind_api |
geoip2/geoip2 package + user ID & license key |
| IP-API | ipapi |
API key (for HTTPS) |
| IPGeolocation | ipgeolocation |
API key |
| IPData | ipdata |
API key |
| IPFinder | ipfinder |
API key |
| IP2Location | ip2location |
API key |
For detailed service configuration, see services documentation.
Configuration
Key options in config/geoip.php:
Caching
GeoIP caches lookups using Laravel's cache system to reduce API calls. Set the cache option to:
all-- cache all lookupssome-- cache only the current user's lookupnone-- disable caching
You can also configure cache_tags, cache_expires (TTL in seconds), and cache_prefix.
Currency Detection
When include_currency is enabled (default), the package resolves the visitor's currency from their country ISO code using the league/iso3166 package.
Default Location
Configure a fallback location returned when a lookup fails or the IP is local/invalid.
Artisan Commands
# Download/update the local GeoIP database (required for maxmind_database) php artisan geoip:update # Clear cached locations php artisan geoip:clear
Changelog
See Releases for what has changed recently.
Contributing
See CONTRIBUTING for details.