承接 diegocopat/laravel-geodata 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

diegocopat/laravel-geodata

Composer 安装命令:

composer require diegocopat/laravel-geodata

包简介

World countries + geographic data (regions, provinces, municipalities with postal codes) + Italian fiscal code (Codice Fiscale) for Laravel. Country-scoped: start with Italy, expand globally.

README 文档

README

World countries + geographic data (regions, provinces, municipalities) + Italian fiscal code (Codice Fiscale) for Laravel. Country-scoped: start with Italy, expand globally.

Features

  • 295 countries with Belfiore codes (includes historical entities for fiscal code retroactive calculation)
  • 20 Italian regions, 107 provinces, ~7,900 municipalities with CAP, coordinates, Belfiore codes
  • Codice Fiscale: generate, validate, and parse Italian fiscal codes
  • Artisan commands for seeding, updating, and statistics
  • Configurable table names to avoid conflicts
  • Laravel 10/11/12/13 compatible

Installation

composer require diegocopat/laravel-geodata

The package auto-discovers the service provider. Publish the config (optional):

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

Run migrations and seed data:

php artisan migrate
php artisan geodata:seed

Configuration

// config/geodata.php

return [
    'tables' => [
        'countries' => 'countries',
        'regions' => 'regions',
        'provinces' => 'provinces',
        'cities' => 'cities',
    ],
    'include_historical_countries' => false,
];

Usage

GeoData Facade

use DiegoCopat\LaravelGeodata\Facades\GeoData;

// Countries
GeoData::countries();                          // active countries
GeoData::countries(includeHistorical: true);   // all 295 including historical
GeoData::searchCountries('Roman');             // search by name
GeoData::italy();                              // get Italy

// Regions & Provinces
GeoData::regions();
GeoData::provinces();
GeoData::provincesByRegion('04');              // by region code

// Cities
GeoData::cities();                             // all active cities
GeoData::citiesByProvince('TN');               // by province code
GeoData::searchCities('Trento');               // search by name
GeoData::searchCities('Rover', 'TN');          // search within province

// Lookups
GeoData::findByBelfiore('L378');               // city: Trento
GeoData::findByBelfiore('Z129');               // country: Romania
GeoData::findByCap('38122');                   // cities by postal code

// Utilities
GeoData::isItaly('IT');                        // true

FiscalCode Facade

use DiegoCopat\LaravelGeodata\Facades\FiscalCode;

// Generate
$cf = FiscalCode::generate([
    'firstname' => 'Mario',
    'lastname' => 'Rossi',
    'gender' => 'M',
    'birth_date' => '1990-01-15',
    'birth_city' => 'Trento',
    'birth_province' => 'TN',
]);
// Returns: RSSMRA90A15L378X

// Generate with direct Belfiore code
$cf = FiscalCode::generate([
    'firstname' => 'Mario',
    'lastname' => 'Rossi',
    'gender' => 'M',
    'birth_date' => '1990-01-15',
    'belfiore_code' => 'L378',
]);

// Generate for foreign-born
$cf = FiscalCode::generate([
    'firstname' => 'Ion',
    'lastname' => 'Popescu',
    'gender' => 'M',
    'birth_date' => '1988-03-10',
    'birth_country' => 'Romania',
]);

// Validate
FiscalCode::validate('RSSMRA90A15L378X'); // true or false

// Parse
$data = FiscalCode::parse('RSSMRA90A15L378X');
// Returns:
// [
//     'surname_code' => 'RSS',
//     'firstname_code' => 'MRA',
//     'birth_year' => '1990',
//     'birth_month' => 1,
//     'birth_day' => 15,
//     'gender' => 'M',
//     'belfiore_code' => 'L378',
//     'birth_date' => '1990-01-15',
//     'birth_place' => 'Trento',
//     'is_foreign' => false,
//     'omocodia_level' => 0,
// ]

Eloquent Models

All models are available for direct queries:

use DiegoCopat\LaravelGeodata\Models\{Country, Region, Province, City};

// Scopes
Country::active()->get();
City::byProvince('TN')->get();
City::byBelfiore('L378')->first();
City::capitals()->get();

// Relationships
$city = City::find(1);
$city->province;
$city->province->region;
$city->province->region->country;

$province = Province::byCode('TN')->first();
$province->cities;
$province->region;

Artisan Commands

Seeding (country-scoped)

# Seed world countries + all available detail data (currently: Italy)
php artisan geodata:seed

# Seed world countries + only Italy detail (regions, provinces, cities)
php artisan geodata:seed --country=it

# Later: add Germany detail without touching Italy
php artisan geodata:seed --country=de

# Multiple countries at once
php artisan geodata:seed --country=it --country=de --country=fr

# Fresh reload — country-scoped (only clears Italy's regions/provinces/cities)
php artisan geodata:seed --country=it --fresh

# Fresh reload everything
php artisan geodata:seed --fresh

# Seed only countries (skip detail data)
php artisan geodata:seed --no-countries --country=it

# List available country data packages
php artisan geodata:seed --list

Data management

# Update data files from remote source
php artisan geodata:update

# Preview changes without downloading
php artisan geodata:update --dry-run

# Show statistics
php artisan geodata:stats

Adding a new country

To add geographic data for a new country, create a directory under database/data/countries/:

database/data/countries/de/
├── regions.json       # German Bundesländer
├── provinces.json     # Kreise/Landkreise
├── cities.json        # Gemeinden
└── cap.json           # Postleitzahlen (optional)

Then run php artisan geodata:seed --country=de. See the it/ directory for the expected JSON format.

Data Sources

License

MIT License. See LICENSE for details.

diegocopat/laravel-geodata 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-20