saeedvaziry / ip2location
IP to Location database
Fund package maintenance!
saeedvaziry
Ko Fi
Installs: 1 442
Dependents: 0
Suggesters: 0
Security: 0
Stars: 29
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.1|^8.0
- ext-zip: *
- illuminate/database: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0
- ip2location/ip2location-php: ^8.2
Requires (Dev)
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0|^8.0|^9.0
- phpunit/phpunit: ^8.0|^9.0|^10.0
README
IP2Location is a small Laravel package that converts IPs to location.
This package is a wrapper to IP2Location.
Installation
composer require saeedvaziry/ip2location
Updating IP database
After the installation, you need to run the following command for updating the IP database.
php artisan ip2location:update
You can also set a scheduler in your app/Console/Kernel.php
to keep it up to date.
Usage
Facade
You can use \SaeedVaziry\IP2Location\Facades\IP2Location
facade to access to all supported methods.
// returns an array \SaeedVaziry\IP2Location\Facades\IP2Location::info($ipAddress); // returns the country full name \SaeedVaziry\IP2Location\Facades\IP2Location::countryName($ipAddress); // returns the country 2 character ISO code \SaeedVaziry\IP2Location\Facades\IP2Location::countryCode($ipAddress);
Helper functions
You may want to access to the methods via helper functions.
// returns an array ip2location_info($ipAddress); // returns the country full name ip2location_country_name($ipAddress); // returns the country 2 character ISO code ip2location_country_code($ipAddress);
If you don't pass the $ipAddress
in both Facade and Helper, The method will extract the IP address from the Http request.
License
IP2Location is licensed under The MIT License (MIT).