interaction-design-foundation / laravel-geoip
Support for multiple Geographical Location services.
Installs: 182 462
Dependents: 3
Suggesters: 0
Security: 0
Stars: 14
Watchers: 1
Forks: 376
Open Issues: 0
pkg:composer/interaction-design-foundation/laravel-geoip
Requires
- php: ^8.1
- ext-curl: *
- illuminate/cache: ^10.0 || ^11.0 || ^12.0
- illuminate/console: ^10.0 || ^11.0 || ^12.0
- illuminate/support: ^10.0 || ^11.0 || ^12.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.50
- geoip2/geoip2: ^3.0
- orchestra/testbench: ^8.8 || ^9.0 || ^10.0
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^11.0 || ^12.0
- rector/rector: ^2.0
- squizlabs/php_codesniffer: ^3.9
- vimeo/psalm: ^6.0
Suggests
- geoip2/geoip2: Required to use the MaxMind database or web service with GeoIP (~2.1).
- monolog/monolog: Allows for storing location not found errors to the log
- dev-main
- 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-defaultLocationResolver
This package is auto-updated.
Last update: 2025-10-16 10:17:46 UTC
README
Determine the geographical location and currency of website visitors based on their IP addresses.
About this fork
We have forked torann/geoip as it’s almost not actively maintained anymore.
This fork works with modern PHP versions only (8.0+), maintained and includes additional features:
- Support modern Laravel and PHP versions
- Better types (native and PHPDoc)
- Safer file and network functionality
- Ability to prefix cache keys (
cache_prefixconfig option) - Ability to change service using
GEOIP_SERVICEenv var - Updated currencies
- More predictable exceptions
But don’t worry, we are following SemVer 2.0. The package migration is straightforward.
Installation
From the command line run:
composer require interaction-design-foundation/laravel-geoip
Publish the configurations
Run this on the command line from the root of your project:
php artisan vendor:publish --provider="InteractionDesignFoundation\GeoIP\GeoIPServiceProvider" --tag=config
and set the GEOIP_SERVICE env variable.
Configuration
Quick breakdown of the two main options in the configuration file.
To find out more simple open the config/geoip.php file.
Service Configuration
To simplify and keep things clean, all third party composer packages, which are needed for a service, are installed separately.
For further configuration options, checkout the services page.
Caching Configuration
GeoIP uses Laravel’s default caching to store queried IP locations. This is done to reduce the number of calls made to the selected service, as some of them are rate limited.
Options:
allall locations are cachedsomecache only the requesting usernonecaching is completely disabled
Usage
There are few options to use the package:
geoip()helper functionInteractionDesignFoundation\GeoIP\Facades\GeoIPfacade
geoip()->getLocation('27.974.399.65'); // Get the location from the provided IP. geoip()->getClientIP(); // Will return the user IP address.
Example of a Location object:
\InteractionDesignFoundation\GeoIP\Location {[ 'ip' => '1.1.1.1', 'iso_code' => 'US', 'country' => 'United States', 'city' => 'New Haven', 'state' => 'CT', 'state_name' => 'Connecticut', 'postal_code' => '06510', 'lat' => 41.28, 'lon' => -72.88, 'timezone' => 'America/New_York', 'continent' => 'NA', 'currency' => 'USD', 'default' => false, ]}
Location class implements \ArrayAccess interface, means you can access properties of the Location object using both object and array access:
$location = geoip()->getLocation(); $city = $location->city; // The same as: $city = $location['city'];
Artisan
Some services require downloading and use a local database to detect Location by IP address. There is a console command to download/update database:
php artisan geoip:update
Some cache drivers offer the ability to clear cached locations:
php artisan geoip:clear
Changelog
Please see Releases for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Contributions
Many people have contributed to the project since its inception.
Thanks to: