pixxet/laravel-geoip-world-cities

Laravel GeoIP World Cities 为 laravel 应用程序提供 MaxMind Free World Cities 数据库。

2.3.1 2017-03-11 16:50 UTC

This package is auto-updated.

Last update: 2024-09-08 07:58:40 UTC


README

Latest Version on Packagist Latest Unstable Version Software License Total Downloads

Laravel GeoIP World Cities 是一个包,为 laravel 应用程序提供 MaxMind 免费世界城市数据库支持。

内容

介绍

包括城市、地区、国家、纬度和经度。此数据库不包含任何 IP 地址。它只是世界上所有城市的列表。

此包仅将 MaxMind 提供的 worldcitiespop.txt.gz 文件中的数据加载到数据库中,并提供一个 City 模型以查询表。

安装前

如果您正在寻找 Laravel 4 版本,请查看 分支 1.0

安装

注意:此包较大,约 40MB,安装和填充数据可能需要一段时间。

pixxet/laravel-geoip-world-cities 添加到 composer.json

"pixxet/laravel-geoip-world-cities": "2.*"

用于最新稳定版本,或

"pixxet/laravel-geoip-world-cities": "dev-master"

用于最新版本。

运行 composer update 以下载 laravel-geoip-world-cities。

编辑 config/app.php 并添加 provider

    'providers' => [
        Pixxet\LaravelGeoIPWorldCities\LaravelGeoIPWorldCitiesServiceProvider::class,
    ]

可选地添加别名。

    'aliases' => [
        'Cities' => Pixxet\LaravelGeoIPWorldCities\Facade::class,
    ]

配置 MySQL 和 PDO,在 config/database.php 中插入以下代码

    'mysql' => [
        'options'   => [PDO::MYSQL_ATTR_LOCAL_INFILE => true],
    ],

发布配置文件,这是您可以更改默认表名的地方

php artisan vendor:publish

发布迁移和种子文件

php artisan cities:migration
php artisan cities:seeder

为确保数据已填充,在 seeds/DatabaseSeeder.php 中插入以下代码

    // Seeding the cities
    $this->call(CitiesTableSeeder::class);
    $this->command->info('Seeded the cities table ...'); 

现在您可以运行

php artisan migrate --seed

运行此命令后,填充的城市表将可用

表结构

示例

此包提供了一个 City 模型,可用于查询数据

    \Pixxet\LaravelGeoIPWorldCities\City::whereCity('Khartoum')->first();

故障排除

如果您在尝试填充时遇到 ReflectionException

    [ReflectionException]                   
    Class CitiesTableSeeder does not exist 

运行

    composer dump-autoload

然后再次尝试。

变更日志

有关最近更改的更多信息,请参阅 CHANGELOG

贡献

有关详细信息,请参阅 CONTRIBUTINGCONDUCT

鸣谢

许可

MaxMind WorldCities 许可

MIT 许可证 (MIT)。有关更多信息,请参阅 许可文件