Download the PHP package sameoldnick/laravel-geolocator without Composer

On this page you can find all versions of the php package sameoldnick/laravel-geolocator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-geolocator

Laravel Geolocator

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.

Table of contents

Requirements

The MaxMind database reader is pure PHP, but MaxMind recommends one of the following extensions:

Installation

The service provider is auto-discovered. Publish the configuration file:

Download the MaxMind databases:

The package does not ship the databases. The command downloads the country, city and ASN editions (both IPv4 and IPv6) into storage/app/geolocation. Lookups throw an InvalidArgumentException when the configured database file is missing, so run the command once after installing, or point the package at databases you already have.

Configuration

Everything lives under the geolocator config key; the values below can be set in config/geolocator.php or through the environment.

Environment variable Default Description
GEOLOCATOR_DRIVER iplocationdb Driver used by the manager
IPLOCATIONDB_COUNTRY_DB_PATH storage/app/geolocation/GeoLite2-Country.mmdb Country edition, IPv4
IPLOCATIONDB_COUNTRY_DB_PATH_V6 storage/app/geolocation/GeoLite2-Country-IPv6.mmdb Country edition, IPv6
IPLOCATIONDB_CITY_DB_PATH storage/app/geolocation/GeoLite2-City.mmdb City edition, IPv4
IPLOCATIONDB_CITY_DB_PATH_V6 storage/app/geolocation/GeoLite2-City-IPv6.mmdb City edition, IPv6
IPLOCATIONDB_ASN_DB_PATH storage/app/geolocation/GeoLite2-ASN.mmdb ASN edition, IPv4
IPLOCATIONDB_ASN_DB_PATH_V6 storage/app/geolocation/GeoLite2-ASN-IPv6.mmdb ASN edition, IPv6
MAXMIND_AUTO_UPDATE true Register the update command on the schedule
MAXMIND_UPDATE_FREQUENCY weekly hourly, daily, weekly, monthly, or a cron expression

The databases are GeoLite2 data redistributed by the ip-location-db project; review that project's licensing and attribution terms before redistributing the files yourself.

Deployment notes

Usage

Quick start

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

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:

Both return the same LocationResult — see Looking up an address for what you can read from it.

Resolving the geolocator

All three resolve the same manager instance. The contract is imported under an as alias because the facade and the contract share their short name. The package also registers a global Geolocator facade alias through extra.laravel.aliases, so the shortest entry point needs no import:

Looking up an address

Each returns a LocationResult, with the editions you did not ask for left as null:

Private, reserved and unparseable addresses return no records, so the result is empty:

When a lookup throws

Lookups are file reads, and three things make them throw rather than return an empty result:

Private, reserved and unparseable addresses are not on that list: they are filtered before the database is queried, so they return an empty result. What an empty result does not mean is that the database is absent — when the file cannot be opened, the lookup throws even for 192.168.1.1.

Resolving the current request

The package registers a geolocate macro on the request:

It takes the first non-private address from $request->getClientIps(), falls back to $request->ip(), and finally to '0.0.0.0' when the request carries no address at all. Pass your own default with $request->geolocate('127.0.0.1').

X-Forwarded-For is only consulted when the request comes from a trusted proxy. Configure this with Laravel's TrustProxies middleware, otherwise the header is ignored and the proxy's own address is used.

Faking lookups in your tests

By default fake() returns an empty result for 10% of public addresses, which is what makes the fake non-deterministic. Pass a different percentage, or 0 when you need real data for every public address:

The fake stays installed for the rest of the test, which is usually what you want since every test gets a fresh container. To hand the facade back to the configured driver mid-test, swap its real root back in:

Writing a custom driver

Implement SameOldNick\Geolocator\Contracts\Geolocator and register it with extend():

Select it with GEOLOCATOR_DRIVER=my-driver, or by setting geolocator.driver in the config file.

A driver name is resolved either by a registered creator (as above) or by a createXDriver() method on the manager. Any other name throws InvalidArgumentException: Driver [x] not supported. — the container is not consulted, so a container binding alone will not register a driver.

Keeping the databases up to date

Downloads are retried across every URL configured for an edition. While MAXMIND_AUTO_UPDATE is enabled the command is also registered on the scheduler (MAXMIND_UPDATE_FREQUENCY, weekly by default) and runs withoutOverlapping().

Events

Event Dispatched when Payload
DatabaseFileUpdated a database file was replaced edition, ipVersion, localPath
DatabaseFileUpdateFailed a file was skipped or every URL failed edition, ipVersion, localPath, reason
DatabaseUpdatesCompleted a full update run finished total, successful, failed, hasFailures()

Each file update also reports progress through the optional callback passed to Updater::update(callable $callback).

The package emits these events but sends no notifications itself — register a listener to notify whatever your application uses (mail, Slack, database notifications).

AI Guidelines

The package ships a Laravel Boost guideline at resources/boost/guidelines/core.blade.php. When a Boost user runs php artisan boost:install, or php artisan boost:update --discover after installing this package, the guideline is merged into their agent's context. It covers the parts that are easy to get wrong: a missing database throwing instead of returning an empty result, the aliasing needed when importing the facade and the contract together, the geolocate request macro, and why X-Forwarded-For must not be parsed by hand.

Nothing depends on Boost in either direction: discovery is by convention from vendor/sameoldnick/laravel-geolocator/resources/boost, so the guideline costs users who do not use Boost nothing at all. Boost renders a guideline as Blade and silently skips one that fails to render, so its snippets are kept inside @verbatim — see CONTRIBUTING.md for how to re-render it after editing.

There is no agent skill to go with it. The package has no multi-step authoring workflow for an agent to improvise — setup is a one-time console task — so a guideline is enough.

Changelog

See CHANGELOG.md for what has changed recently. This project follows Semantic Versioning.

Contributing

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

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.


All versions of laravel-geolocator with dependencies

PHP Build Version
Package Version
Requires php Version ^8.4
illuminate/contracts Version ^11.0||^12.0||^13.0
maxmind-db/reader Version ^1.14.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package sameoldnick/laravel-geolocator contains the following files

Loading the files please wait ...