项目作者: adrianorsouza

项目描述 :
Laravel package to get the details about Region, City and Country for a given IP Address.
高级语言: PHP
项目地址: git://github.com/adrianorsouza/laravel-geolocation.git
创建时间: 2019-08-13T22:50:25Z
项目社区:https://github.com/adrianorsouza/laravel-geolocation

开源协议:BSD 3-Clause "New" or "Revised" License

下载


Laravel GeoLocation Package

Laravel package to get the details about Region, City and Country for a given IP Address.

This package is a wrapper for IpInfo Provider, however we have plan to implement a driver for
MaxMind GeoIP2 databases.

Install

  1. composer require adrianorosa/laravel-geolocation

This package supports the latest version of Laravel, for now 5.8+ was tested, but older versions should work fine.

As of Laravel 5.5 there is no need to add the ServiceProvider within the AppServiceProvider array.
Laravel loads this provider using Package Discovery.

Usage

There is no need to additional setup to start using, once you install it via composer you can call the Facade:

  1. <?php
  2. use Adrianorosa\GeoLocation\GeoLocation;
  3. $details = GeoLocation::lookup('8.8.8.8');
  4. echo $details->getIp();
  5. // 8.8.8.8
  6. echo $details->getCity();
  7. // Mountain View
  8. echo $details->getRegion();
  9. // California
  10. echo $details->getCountry();
  11. // United States
  12. echo $details->getLatitude();
  13. // 37.386
  14. echo $details->getLongitude();
  15. // -122.0838
  16. var_dump($details->toArray());
  17. // Array
  18. // (
  19. // [city] => Mountain View
  20. // [region] => California
  21. // [country] => United States
  22. // [countryCode] => US
  23. // [latitude] => 37.386
  24. // [longitude] => -122.0838
  25. //)

Console Command

To display details about an Ip or Your current network Ip Address you may use the artisan command:

  1. php artisan geolocation:lookup --ip 8.8.8.8
  2. +---------+---------------+------------+----------------+-------------+----------+-----------+
  3. | ip | city | region | country | countryCode | latitude | longitude |
  4. +---------+---------------+------------+----------------+-------------+----------+-----------+
  5. | 8.8.8.8 | Mountain View | California | Estados Unidos | US | 37.386 | -122.0838 |
  6. +---------+---------------+------------+----------------+-------------+----------+-----------+

Override Configuration and translations

This package comes with a little configuration for IpInfo and translations for Country Names.

You can stick with default values, which works fine, or publish using the following commands:

Publish all config and translations

  1. php artisan vendor:publish

Publish config

  1. php artisan vendor:publish --tag=geolocation-config

Publish translations

  1. php artisan vendor:publish --tag=geolocation-translations

Author

Adriano Rosa (https://adrianorosa.com)

Licence

Copyright © 2021, Adriano Rosa info@adrianorosa.com
All rights reserved.

For the full copyright and license information, please view the LICENSE
file that was distributed within the source root of this project.