Search by

sameoldnick / laravel-geolocator

SameOldNick

A Laravel package for integrating geolocation services with your application.

Package info

github.com/SameOldNick/laravel-geolocator

Homepage

pkg:composer/sameoldnick/laravel-geolocator

Statistics

Installs: 230

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 3

v2.0.0 2026-09-29 05:12 UTC

This package is auto-updated.

Last update: 2026-10-03 21:26:34 UTC


README

Tests codecov Packagist Version

An offline IP geolocation package for Laravel, backed by MaxMind databases. Look up the country, city and ASN behind an IP address, resolve the location of the current request, and keep the databases up to date with a scheduled Artisan command.

Requirements

  • PHP 8.4 or newer
  • Laravel 11, 12 or 13 (illuminate/contracts ^11.0 || ^12.0 || ^13.0)
  • Composer

The MaxMind database reader is pure PHP. ext-bcmath or ext-gmp (for the pure PHP decoder) and ext-maxminddb (a faster C decoder) are recommended but optional. See Installation for the full setup, including deployment notes.

Installation

composer require sameoldnick/laravel-geolocator
php artisan vendor:publish --tag=geolocator-config
php artisan geolocator:update-iplocationdb

The service provider is auto-discovered. The package does not ship the databases, so run the update command once per environment; lookups throw an InvalidArgumentException when a configured database file is missing. Every path and environment variable is in Configuration.

Quick start

Once the databases are in place, the shortest working path is a route that resolves the caller:

use Illuminate\Http\Request;

Route::get('/where-am-i', function (Request $request) {
    $location = $request->geolocate();

    return [
        'ip' => $location->ipAddress,
        'country' => $location->country?->countryCode,
        'city' => $location->city?->city,
        'asn' => $location->asn?->organization,
    ];
});

That is the whole integration. The service provider, the geolocate macro and the Geolocator facade alias are registered for you, there is no API key to configure, and a lookup is a file read rather than an HTTP call.

To look up an address other than the caller's, call the facade directly:

use SameOldNick\Geolocator\Facades\Geolocator;

$location = Geolocator::lookup('8.8.8.8');

Both return the same LocationResult — see Usage for what you can read from it.

Documentation

This file is the entry point; the wiki holds the detail.

Changelog

See CHANGELOG.md for what has changed recently, and UPGRADING.md for the steps each major version needs. This project follows Semantic Versioning.

Contributing

Pull requests are welcome. Please keep the suite green and the code style applied before opening one:

composer test      # the test suite
composer format    # the code style

See CONTRIBUTING.md for the development environment, the full set of checks, the test layout and the documentation rules.

Security

Please review the security policy before reporting a vulnerability, and do not open a public issue for security problems.

License

This package is open-sourced software licensed under the MIT license.