定制 slivka-b/laravel-geonames 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

slivka-b/laravel-geonames

Composer 安装命令:

composer require slivka-b/laravel-geonames

包简介

[fork] The package allows integrating geonames database with a Laravel application.

README 文档

README

Currently the work in progress. It will receive updates with possible breaking changes. Not recommended using in production environments yet.

The package allows integrating geonames database with a Laravel application.

🗒️ Description

This package is a fork of nevadskiy/laravel-geonames.

The package is very useful for applications that rely on the geo data.

By default, the package provides 5 tables: continents, countries, divisions, cities and translations and fills them with data from the geonames service.

It also allows to keep the data up-to-date, so the package fetches all daily modifications provided by the geonames service and use them to synchronize your own database.

You can also set up the package to seed only data that belongs to specific countries, disable unneeded tables, set up minimal population filter and use your own custom models.

Translations are powered by the imcity-tech/laravel-translatable.

🔌 Installation

composer require imcity-tech/laravel-geonames

✅ Requirements

  • Laravel 9.0 or newer
  • PHP 8.0 or newer

🔨 Usage

Default structure and behaviour

  • Migrate the database
php artisan migrate
  • Run insert process
php artisan geonames:insert

It will insert download and insert the geonames dataset into your database.

Note that the insert process may take some time. On average, it is about 15 minutes (without downloading time).

Schedule updates

Add the following code to your console kernel (app/Console/Kernel.php) if you want to receive geonames daily updates.

protected function schedule(Schedule $schedule)
{
    $schedule->command('geonames:update')->dailyAt('4:00');
}

Note, that time is specified for the UTC timezone, so if you run server on another timezone, you need to convert time according to it.

Configure custom structure

If you want to configure package according to your needs, you need to publish the package configuration first.

php artisan vendor:publish --tag=geonames-config

Specifying source

You can choose appropriate data source for seeding as one of SOURCE_ALL_COUNTRIES, SOURCE_SINGLE_COUNTRY or SOURCE_ONLY_CITIES.

The default is SOURCE_ALL_COUNTRIES that indicates to fetch data from the allCountries.zip file. It contains all 4 models (continents, countries, divisions and cities). You can configure filters in the geonames configuration file to specify countries that is going to be seeded and minimal population.

The SOURCE_SINGLE_COUNTRY source is used to fetch data from country-based files (e.g. US.zip). The continents table will not be seeded with this source. You can specify which country (or countries) you are going to seed specifying countries filter in the geonames configuration file.

The SOURCE_ONLY_CITIES source is used to fetch data from city-based files (e.g. cities500.zip). There is only cities table available with this source type. You can specify minimal population filter to indicate which file it is going to fetch by population. It is also possible to use countries filter to seed cities that belongs only to specific countries.

Specifying filters

By default, there are two filters which you can use to filter data being seeded.

Countries filter

The countries filter is used to filter data that belongs only to specific country (or countries). If the SOURCE_SINGLE_COUNTRY source is specified, this filter will be used to download a country-based data source. The default is * that indicates that all countries are allowed. Multiple countries can be specified as an array of ISO country codes.

Example:

'filters' => [
    'countries' => ['AU', 'US']
]

Population filter

The population filter is used to filter cities by the indicated minimal population. If the SOURCE_ONLY_CITIES source is specified, this filter will be used to download a city-based data source. Any value from 0 and higher has be used, but in combination with the SOURCE_ONLY_CITIES source, available values are only 500, 1000, 5000 and 15000.

Example:

'filters' => [
    'population' => 15000
]

Overriding models

Most likely you will need your own models with their own behaviour and relations instead of provided ones by default.

To override them, use models key in the geonames configuration file.

If you are not going to use any model, you can switch the value to false and then corresponding tables will not be migrated at all.

For example, most applications probably will not need continent model.

'models' => [
    'continent' => false,
    'country' => App\Models\Country::class,
    'division' => App\Models\Division::class,
    'city' => App\Models\City::class,
],

Overriding migrations

To rename tables or remove unnecessary fields, you can publish migrations and edit them before execution migrations command.

  • To publish default migrations, use the following command:
php artisan vendor:publish --tag=geonames-migrations
  • Then disable default migrations from being migrated, setting default_migrations to false in the geonames configuration file.
'default_migrations' => false

Inserting custom structure

  • After configuring source and filters, you can execute migrations command. It will determine which tables should be migrated and create them in the database.
php artisan migrate
  • Then you can run insert command.
php artisan geonames:insert

Reinserting dataset

Sometimes you may need to delete all data and reinsert it again. To do it, pass the --reset option to geonames:insert command.

php artisan geonames:insert --reset

📑 Changelog

Please see CHANGELOG for more information what has changed recently.

☕ Contributing

Please see CONTRIBUTING for more information.

🔓 Security

If you discover any security related issues, please e-mail me instead of using the issue tracker.

📜 License

The MIT License (MIT). Please see LICENSE for more information.

slivka-b/laravel-geonames 适用场景与选型建议

slivka-b/laravel-geonames 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 85 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「database」 「geo」 「laravel」 「countries」 「geonames」 「cities」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 slivka-b/laravel-geonames 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 slivka-b/laravel-geonames 我们能提供哪些服务?
定制开发 / 二次开发

基于 slivka-b/laravel-geonames 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 85
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 24
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-21