midnite81 / geolocation
A laravel package which wraps the IP Info DB and IP2Location Services
Installs: 17 514
Dependents: 0
Suggesters: 0
Security: 0
Stars: 38
Watchers: 3
Forks: 11
Open Issues: 0
Requires
- php: >=8.1
- ext-json: *
- guzzlehttp/guzzle: ^7.0
- midnite81/core: ^1.0
Requires (Dev)
- laravel/pint: ^1.1
- mockery/mockery: ^1.0
- orchestra/testbench: ^6.3
- pestphp/pest: ^1.21
- pestphp/pest-plugin-parallel: ^1.2
- php-coveralls/php-coveralls: ^2.4
- phpstan/phpstan: ^1.8
- phpunit/phpunit: ^9.4
- squizlabs/php_codesniffer: ^3.5
README
A IP Info DB integration for Laravel
Versioning
Upgrading to v4.0
Please note:
- version 4 brings in the ability to wrap both the IpInfoDb service (as was available in previous versions) and the Ip2Location service. IpInfoDb are not accepting new registrations and are asking users to register at Ip2Location instead.
- version 4 minimum requirements are php 8.1 to make use of the additional features php 8.1 brings, such as enums and better type safety.
- version 4 has an updated config file. If you are upgrading, I would suggest checking out the config file and updating your local instance of it.
- a change has been made to the caching from minutes to seconds.
Installation
If installing on anything below PHP 8.1, please checkout the v2 or v3 branch and follow the instructions on the readme for that branch. Please note ip2location is not supported on previous versions of this package
This package requires PHP 8.1+, and includes a Laravel Service Provider.
To install through composer include the package in your composer.json
.
"midnite81/geolocation": "^4.0"
Run composer install
or composer update
to download the dependencies, or you can run
composer require midnite81/geolocation
.
Laravel Integration
This package makes use of Laravel's auto package loader, so you shouldn't need to add this
to your config/app.php file. However, if you've disabled this then you'll need to add the
GeoLocation service provider to the list of service providers
in app/config/app.php
.
'providers' => [
Midnite81\GeoLocation\GeoLocationServiceProvider::class
];
Publish the config and migration files using
php artisan vendor:publish --provider="Midnite81\GeoLocation\GeoLocationServiceProvider"
Configuration File
Once you have published the config files, you will find a geolocation.php
file in the
config
folder. You should look through these settings and update these where necessary.
Env
You will need to add the following to your .env
file and update these with your own
settings. Please note you will only need to fill in the api key for the service you are using.
GEOLOCATION_IPINFODB_API_KEY=<ip_info_db_api_key> GEOLOCATION_IP2LOCATION_API_KEY=<ip2location_api_key> GEOLOCATION_CACHE=<duration_in_seconds>
Get your GeoLocation API Key
Before using this package you'll need to obtain an API Key from either IpInfoDb which is no longer accepting new registrations or Ip2Location.
Once you have signed up you will need to add your api key to the relevant .env
key; GEOLOCATION_IPINFODB_API_KEY
for
IpInfoDb or GEOLOCATION_IP2LOCATION_API_KEY
for Ip2Location.
Caching
This package allows you to cache responses, however it is your responsibility to ensure you're not breaking any terms and conditions of use.
Rate Limiting
This package does not set any rate limiting internally. You should ensure that your application adheres to any rate limiting set by your chosen provider.