Download the PHP package atldays/laravel-geo without Composer
On this page you can find all versions of the php package atldays/laravel-geo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download atldays/laravel-geo
More information about atldays/laravel-geo
Files in atldays/laravel-geo
Package laravel-geo
Short Description Retrieve visitor location from IP addresses in Laravel using online and local services, including country, city, continent, and coordinates.
License MIT
Homepage https://github.com/atldays/laravel-geo
Informations about the package laravel-geo
Laravel Geo
atldays/laravel-geo retrieves visitor location from IP addresses using both online and local services. No matter which provider is used, the result is normalized geo data such as country, city, continent, and coordinates.
You can use it directly from the current request, from any Request instance, or from an explicit IP address.
All supported drivers are normalized into the same strongly typed GeoContract, so you work with consistent DTOs instead of provider-specific arrays.
Drivers
The package includes these drivers out of the box:
The default driver is IpApi, because it lets developers install the package and see real results immediately.
Installation
Publish the config file if you want to customize driver order or provider settings:
Quick Start
Current request geo data
Use the Geo facade when you want data for the current request.
Available facade methods match GeoContract:
Geo::ip()Geo::provider()Geo::continent()Geo::country()Geo::city()Geo::registeredCountry()Geo::accuracyRadius()Geo::latitude()Geo::longitude()Geo::timeZone()Geo::postalCode()Geo::data()Geo::toArray()
Explicit IP and request lookups
Use the GeoManager facade when you want to resolve a specific IP or request instance.
GeoManager::ip() and GeoManager::request() return Atldays\Geo\Contracts\GeoContract.
Dependency Injection
You can also resolve the current geo result through dependency injection using GeoContract.
Configuration
The main config file is config/geo.php.
Default driver and fallbacks
You can switch to MaxMind and keep IpApi as a fallback:
Drivers are resolved in this order:
geo.driver- every class from
geo.fallbacks
If a driver throws DriverUnavailableException, the manager moves to the next configured driver.
Request Macros
The package registers three request macros:
request()->geo()request()->realIp()request()->fakeIp()
GeoManager::request() uses:
fakeIp()when debug mode is enabled and a valid fake IP is present- otherwise
realIp()
The fake IP input key is configurable:
That makes local testing convenient:
You can also resolve geo data directly from any Request instance:
IP-API
IP-API is the default driver because it gives immediate feedback after installation.
You do not need to create credentials or download a local database to start using it.
If you install the package and keep the default configuration, Geo and GeoManager will already resolve data through IpApi.
Example:
Config:
This is the recommended choice when you want to try the package quickly without creating external credentials or downloading a local database first.
MaxMind
MaxMind uses a local .mmdb database and is the better choice when you want stable local lookups backed by a real database file.
To use it, you need a MaxMind account and credentials for the GeoLite2 download service.
GeoLite2 is free, so developers can start with the free MaxMind offering and still get a solid local integration.
Config:
MaxMind setup flow
- Create or sign in to your MaxMind account.
- Generate a license key for GeoLite2 downloads.
- Add
MAXMIND_ACCOUNT_IDandMAXMIND_LICENSE_KEYto your environment. - Switch your
geo.drivertoMaxMind::classif you want it as the primary driver. - Run the update command to download the local database.
Example environment:
Updating the MaxMind database
Run:
Force a fresh download even if the local file appears current:
The updater stores:
- the downloaded
.mmdbfile - a metadata JSON file next to it
UpdateResult is generic and only reports:
- whether the resource was downloaded
- the local stored path
- the metadata path
Source-specific details such as edition_id, download_url, or remote_last_modified live inside metadata instead of the shared DTO.
Geo Data
Resolved geo data is normalized into GeoContract.
That means driver-specific payloads are not exposed as arbitrary top-level structures. Every supported driver is mapped into the same typed result shape.
Depending on the driver and available source data, you may receive:
- provider
- continent
- country
- city
- registered country
- accuracy radius
- latitude and longitude
- time zone
- postal code
- raw provider payload
Nested geo objects are normalized too:
continent()returnsContinentContractIt provides a strict name, continent code, and nullable external ID.country()andregisteredCountry()returnCountryContractThey provide a strict name, ISO code, normalized continent object, and nullable external ID. They also exposedefinition()for resolving rich country metadata throughCountryDefinitionContract.city()returnsCityContractIt provides a strict name, normalized country object, subdivisions collection, and nullable external ID.- city subdivisions implement
SubdivisionContractThey provide a strict name, ISO code, and nullable external ID.
provider() returns the driver name that produced the result, such as MaxMind or IpApi.
externalId is provider-specific metadata. For MaxMind, it maps to geoname_id. For IpApi, it is null. It should not be treated as a globally stable cross-provider identifier.
country()->definition() resolves rich country metadata through the configured country definition provider.
By default the package points to Atldays\Geo\CountryDefinitions\Rinvex, which requires the optional rinvex/countries package to be installed.
Install it when you want to use country definitions:
Config:
The configured provider is resolved through CountryDefinitionManager, so additional providers can be added later without changing the CountryContract API.
Example:
If the configured provider depends on an optional package that is not installed, the package throws DefinitionUnavailable.
Some drivers may return partial data. A lookup can still be successful even if only part of the geo payload is available.
Public API
Main public package entry points:
Atldays\Geo\Facades\GeoAtldays\Geo\Facades\GeoManagerAtldays\Geo\Contracts\GeoContractAtldays\Geo\Contracts\DriverContractAtldays\Geo\Contracts\UpdatableDriverContractAtldays\Geo\Contracts\UpdateResultContract
Testing
Run the standard test suite:
Run formatting checks:
Run live driver checks:
Live tests cover real providers and may require external credentials, especially for MaxMind.
License
The MIT License (MIT). Please see LICENSE.md for more information.
All versions of laravel-geo with dependencies
guzzlehttp/guzzle Version ^7.9
illuminate/console Version ^10.0|^11.0|^12.0|^13.0
illuminate/contracts Version ^10.0|^11.0|^12.0|^13.0
illuminate/filesystem Version ^10.0|^11.0|^12.0|^13.0
illuminate/http Version ^10.0|^11.0|^12.0|^13.0
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
maxmind-db/reader Version ~1.0
spatie/laravel-data Version ^4.21
spatie/laravel-package-tools Version ^1.93