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
- DarioCorno/database_comuni_italiani — ISTAT-based Italian geographic data
- Garda Informatica — Reference
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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 diegocopat/laravel-geodata 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Manage regions in magento2 addresses
List of all countries with names and ISO 3166-1 codes in all languages and data formats for Laravel
Laravel 5.2 package that provides basic geographical data like Countries, Regions and Cities.
Add generic 'geo-zones' a full list of country specific regions and the ability to categorise them into zones
List of Italian Regioni (Regions), Province (Provinces), and Comuni (Municipalities) with data from Istat
Small PHP client library for geo api fr
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 38
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-03-20