定制 plin-code/laravel-istat-foreign-countries 二次开发

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

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

plin-code/laravel-istat-foreign-countries

Composer 安装命令:

composer require plin-code/laravel-istat-foreign-countries

包简介

Laravel package for importing and managing foreign countries data from ISTAT

README 文档

README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

A Laravel package for importing and managing foreign countries data from ISTAT (Italian National Institute of Statistics).

Features

  • 🌍 Import continents, geographical areas, and foreign countries from ISTAT
  • 🔗 Eloquent models with hierarchical relationships
  • ⚡ Artisan command for easy data import
  • 🔧 Fully configurable via configuration file
  • 🆔 UUID primary keys and soft deletes support
  • 🏷️ Multiple coding standards support (ISTAT, ISO, MIN, AT)

Requirements

  • PHP 8.3+
  • Laravel 12.0+
  • league/csv 9.0+
  • guzzlehttp/guzzle 7.0+

Installation

composer require plin-code/laravel-istat-foreign-countries

Quick Start

  1. Install the package:
composer require plin-code/laravel-istat-foreign-countries
  1. Publish the configuration:
php artisan vendor:publish --provider="PlinCode\IstatForeignCountries\IstatForeignCountriesServiceProvider"
  1. Run migrations:
php artisan migrate
  1. Import the data:
php artisan foreign-countries:import

That's it! You now have all foreign countries data in your database.

Configuration

Publish the configuration file:

php artisan vendor:publish --provider="PlinCode\IstatForeignCountries\IstatForeignCountriesServiceProvider"

Usage

Data Import

To import all foreign countries data from ISTAT:

php artisan foreign-countries:import

Models

The package provides three Eloquent models:

Continent

use PlinCode\IstatForeignCountries\Models\ForeignCountries\Continent;

$continent = Continent::where('name', 'Europa')->first();
$areas = $continent->areas;
$countries = $continent->countries;

Area

use PlinCode\IstatForeignCountries\Models\ForeignCountries\Area;

$area = Area::where('name', 'Unione europea')->first();
$countries = $area->countries;
$continent = $area->continent;

Country

use PlinCode\IstatForeignCountries\Models\ForeignCountries\Country;

// Find by ISO alpha2
$country = Country::where('iso_alpha2', 'FR')->first();

// Find by ISO alpha3
$country = Country::where('iso_alpha3', 'FRA')->first();

// Find by ISTAT code
$country = Country::where('istat_code', '215')->first();

// Access relationships
$continent = $country->continent;
$area = $country->area;

// Check type
if ($country->isState()) {
    echo "This is a state";
}

if ($country->isTerritory()) {
    echo "This is a territory";
    $parent = $country->parentCountry;
}

// Get territories of a country
$france = Country::where('iso_alpha2', 'FR')->first();
$territories = $france->territories;

Facade Usage

use PlinCode\IstatForeignCountries\Facades\IstatForeignCountries;

// Import data programmatically
$count = IstatForeignCountries::import();

Available Codes

Each country includes multiple international coding standards:

  • ISTAT Code: Italian statistical code
  • ISO Alpha-2: Two-letter country code (e.g., "FR")
  • ISO Alpha-3: Three-letter country code (e.g., "FRA")
  • AT Code: Italian territorial code

Database Structure

Continents

  • id (UUID, primary key)
  • name (string)
  • istat_code (string, unique)
  • created_at, updated_at, deleted_at

Areas

  • id (UUID, primary key)
  • continent_id (UUID, foreign key)
  • name (string)
  • istat_code (string, unique)
  • created_at, updated_at, deleted_at

Countries

  • id (UUID, primary key)
  • continent_id (UUID, foreign key)
  • area_id (UUID, foreign key)
  • parent_country_id (UUID, foreign key, nullable)
  • type (string: 'S' for State, 'T' for Territory)
  • name (string: Italian name)
  • istat_code (string, unique)
  • iso_alpha2 (string, 2 chars)
  • iso_alpha3 (string, 3 chars)
  • at_code (string)
  • created_at, updated_at, deleted_at

Relationships

  • ContinenthasManyArea
  • ContinenthasManyCountry
  • AreabelongsToContinent
  • AreahasManyCountry
  • CountrybelongsToContinent
  • CountrybelongsToArea
  • CountrybelongsToCountry (parent country, for territories)
  • CountryhasManyCountry (territories)

Configuration

The config/istat-foreign-countries.php file allows you to customize:

  • Database connection: Specify a custom database connection
  • Table names: Customize the database table names
  • Model classes: Use your own model classes by extending the base ones
  • CSV URL: Change the ISTAT data source URL
  • Temporary file name: Customize the cache file name

Example Configuration

return [
    'database_connection' => null,

    'tables' => [
        'continents' => 'continents',
        'areas' => 'areas',
        'countries' => 'countries',
    ],

    'models' => [
        'continent' => \App\Models\Continent::class,
        'area' => \App\Models\Area::class,
        'country' => \App\Models\Country::class,
    ],

    'import' => [
        'csv_url' => 'https://www.istat.it/storage/codici-unita-amministrative/Elenco-codici-e-denominazioni-unita-territoriali-estere.csv',
        'temp_filename' => 'istat_foreign_countries.csv',
    ],
];

Testing

Run the test suite:

composer test

The package includes:

  • ✅ Unit tests for models and relationships
  • ✅ Feature tests for the import service
  • ✅ Mocked HTTP requests (no external dependencies)
  • ✅ PHPStan static analysis (Level 5)
  • ✅ Pest PHP testing framework
  • ✅ Architecture tests

Run Static Analysis

composer analyse

Code Style Formatting

composer format

Contributing

  1. Fork the project
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Credits

Data source: ISTAT - Italian National Institute of Statistics

License

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

plin-code/laravel-istat-foreign-countries 适用场景与选型建议

plin-code/laravel-istat-foreign-countries 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.32k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 11 月 10 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 plin-code/laravel-istat-foreign-countries 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 2.32k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 29
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-10