Download the PHP package dive-be/laravel-geo without Composer
On this page you can find all versions of the php package dive-be/laravel-geo. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-geo
🌍 - Translate IP addresses into geo locations
This package will assist you in grabbing a visitor's country.
What problem does this package solve?
Depending on the context of your application, you may want to display content tailored for a specific country/region of the visitor. This package will help with providing a sensible default using IP addresses if it is a first time visit for a user.
Installation
You can install the package via composer:
You will also need to install GeoIP2 if you're planning to use their services:
You can publish the config file with:
This is the content of the config file:
Usage
First, you will have to decide which service to use.
Detectors
When you've decided, set the GEO_DETECTORS_DRIVER
environment variable to the correct value.
Refer to the configuration file for the right values.
GeoIP2 Databases
- Generate a license key
- Set the
GEO_DETECTORS_MAXMIND_DB_LICENSE_KEY
environment variable to your license key
Auto updating local database
IP address ranges tend to become out of date over time. Therefore, this package also provides a convenient update command which you can schedule to run once a week to keep everything fresh.
Only applicable if using MaxMind's GeoIP2 Databases.
GeoIP2 Precision Web Services
- Get
account_id
&license_key
- Set the
GEO_DETECTORS_MAXMIND_WEB_ACCOUNT_ID
&GEO_DETECTORS_MAXMIND_WEB_LICENSE_KEY
environment variables
IP 2 Country
This is a free service. You don't have to configure anything.
Note: it is strongly recommended to enable caching for this driver.
Static
The static driver is meant for usage during local development and testing. You should not use it in any other environment as it is always going to return the fallback value.
Detecting a visitor's geo location
Add the DetectGeoLocation
(or alias geo
) middleware to your kernel's web
middleware stack and you are good to go.
If your app is behind a proxy/load balancer, make sure DetectGeoLocation
is defined after TrustProxies
.
Retrieving the detected country 🗺
There are multiple ways to retrieve the detected ISO alpha-2 country code.
Facade
or using the alias
Helper
Dependency injection
Transforming the detected geo location 🔷
It is a high probability that you'd like to transform the ISO alpha-2 country code into your own Eloquent model or value object
after calling get
on the repository class. You may define your own CountryTransformer
which implements the Transformer
interface
and simply returns the desired object.
e.g.
After defining the class, make sure to provide the FQCN in the configuration file.
Overwriting existing country ✍🏼
At any point in time, you may overwrite the detected country code. Simply call:
Clearing the cache 🔥
When enabled, the translated addresses will be held in cache for a certain amount of time defined in the configuration file. If you'd like to wipe these translations, use the command:
Note: the cache driver must support tagging or else everything will be cleared when the command above is run.
Extending the detectors 👣
If the default drivers do not fulfill your needs, you may extend the DetectorManager
with your own custom drivers:
Testing 🔎
This package offers fake implementations of the Repository
& Detector
contracts so you can make assertions in your unit tests and make sure you ship that bug-free code 💪. Just call fake
on either of them and you're set:
Testing (package)
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
Credits
- Muhammed Sari
- All Contributors
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-geo with dependencies
illuminate/cache Version ^11.0
illuminate/console Version ^11.0
illuminate/contracts Version ^11.0
illuminate/cookie Version ^11.0
illuminate/http Version ^11.0
illuminate/support Version ^11.0