Download the PHP package stevebauman/location without Composer
On this page you can find all versions of the php package stevebauman/location. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stevebauman/location
More information about stevebauman/location
Files in stevebauman/location
Package location
Short Description Retrieve a user's location by their IP Address
License MIT
Informations about the package location
Location
Retrieve a visitor's location from their IP address using various services.
- Requirements
- Installation
- Usage
- Drivers
- Upgrading from v6
- Versioning
Requirements
- PHP >= 8.1
- Laravel >= 8.0
Installation
Install location using composer require
:
Publish the configuration file (this will create a location.php
file inside the config
directory):
Usage
Retrieve a client's location
Important:
- This method retrieves the user's IP address via
request()->ip()
.- In the default configuration,
testing.enabled
is active, the returned IP address is in the USA. Disable it to get the client's real IP address.
Retrieve the location of a specific IP address
Drivers
Available Drivers
Available drivers:
Setting up MaxMind with a self-hosted database (optional)
We encourage setting up MaxMind as a fallback driver using a local database, as it allows you to bypass any throttling that could occur from using external web services.
To set up MaxMind to retrieve the user's location from your own server, you must:
- Create a maxmind account and sign in
- Click "Manage License Keys" from the profile menu dropdown
- Generate a new license key
- Copy the license key and save it into your
.env
file using theMAXMIND_LICENSE_KEY
key - Run
php artisan location:update
to download the latest.mmdb
file into yourdatabase/maxmind
directory - That's it, you're all set!
Note: Keep in mind, you'll need to update this file by running
location:update
on a regular basis to retrieve the most current information from your visitors.
Fallback Drivers
In the config file, you can specify as many fallback drivers as you wish. It is
recommended to configure the MaxMind driver with the local database .mmdb
file (mentioned above), so you are alwaysretrieving some generic location
information from the visitor.
If an exception occurs trying to grab a driver (such as a 400/500 error if the providers API changes), it will automatically use the next driver in line.
Creating your own drivers
To create your own driver, simply create a class in your application, and extend the abstract Driver:
Then, insert your driver class name into the configuration file:
Upgrading from v6
In version 7, the codebase has been updated with strict PHP types,
updated PHP and Laravel version requirements, an updated Driver
structure, as well as a small configuration addition.
Configuration
In version 7, location drivers can now implement an Updatable
interface
that allows them to be updated using the location:update
command.
Currently, only the MaxMind driver supports this.
To update your configuration file to be able to download the latest
MaxMind database file automatically, insert the below url
configuration option in your config/location.php
file:
Once done, you may execute the below artisan command to download the latest .mmdb
file:
Drivers
In version 7, the codebase has been updated with strict PHP
types, updated PHP and Laravel version requirements,
and an updated Driver
structure.
If you have created your own custom driver implementation,
you must update it to use the base Driver
or HttpDriver
class.
If you're fetching a location using an HTTP service, it
may be useful to extend the HttpDriver
to reduce
the code you need to write:
Versioning
Location is versioned under the Semantic Versioning guidelines as much as possible.
Releases will be numbered with the following format:
And constructed with the following guidelines:
- Breaking backward compatibility bumps the major and resets the minor and patch.
- New additions without breaking backward compatibility bumps the minor and resets the patch.
- Bug fixes and misc changes bumps the patch.
Minor versions are not maintained individually, and you're encouraged to upgrade through to the next minor version.
Major versions are maintained individually through separate branches.
All versions of location with dependencies
ext-json Version *
ext-curl Version *
geoip2/geoip2 Version ^2.0
guzzlehttp/guzzle Version ^7.0
illuminate/support Version ^8.0|^9.0|^10.0|^11.0