承接 usamamuneerchaudhary/country-city-state 相关项目开发

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

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

usamamuneerchaudhary/country-city-state

Composer 安装命令:

composer require usamamuneerchaudhary/country-city-state

包简介

Country City State Data Provider for Laravel 12+

README 文档

README

World's Country City State Data for Laravel ^12.0 with PHP ^8.3|^8.4 and phone codes support as per ISO standards.

Latest Version on Packagist Total Downloads Monthly Downloads License PHP Version Laravel Version

🚀 Requirements

  • PHP: ^8.3|^8.4
  • Laravel: ^12.0

📦 Installation

You can install the package via composer:

composer require usamamuneerchaudhary/country-city-state

🔧 Setup

1. Publish Assets

# Publish migrations, models, helpers, and seeders
php artisan vendor:publish --tag=CountryCityState

# Publish configuration file
php artisan vendor:publish --tag=config

2. Run Migrations

php artisan migrate

3. (Optional) Run Seeder

php artisan db:seed --class=UsamaMuneerChaudhary\\CountryCityState\\seeds\\CountryCityStateTableSeeder

💡 Usage

Using the Facade

use UsamaMuneerChaudhary\CountryCityState\Facades\CountryCityState;

// Get all active countries
$countries = CountryCityState::getCountries();

// Get states by country ID
$states = CountryCityState::getStatesByCountry(1);

// Get cities by state ID
$cities = CountryCityState::getCitiesByState(1);

// Get phone codes by country ID
$phoneCodes = CountryCityState::getPhoneCodesByCountry(1);

// Find country by ISO code
$country = CountryCityState::findCountryByIso('US');

Using the Service Container

$service = app('country-city-state');
$countries = $service->getCountries();

Direct Model Usage

use UsamaMuneerChaudhary\CountryCityState\Models\Country;
use UsamaMuneerChaudhary\CountryCityState\Models\State;
use UsamaMuneerChaudhary\CountryCityState\Models\City;

// Find country by ISO code
$country = Country::where('iso_code2', 'US')->first();

// Get all states for a country
$states = $country->states;

// Get all cities for a state
$cities = $states->first()->cities;

// Find state by name
$state = State::where('name', 'California')->first();

// Find city by name
$city = City::where('name', 'Los Angeles')->first();

Working with Relationships

// Country -> States -> Cities
$country = Country::find(1);
$states = $country->states; // HasMany relationship

$state = $states->first();
$cities = $state->cities; // HasMany relationship

// Reverse relationships
$city = City::find(1);
$state = $city->state; // BelongsTo relationship
$country = $state->country; // BelongsTo relationship

⚙️ Configuration

The package configuration file will be published to config/country-city-state.php. You can customize:

  • Default Status: Set default status for new records (active/inactive)
  • Table Names: Customize database table names if needed
  • Cache Settings: Enable/disable caching and set TTL
  • Seeder Behavior: Control seeder truncation behavior
return [
    'default_status' => 'active',
    'tables' => [
        'countries' => 'countries',
        'states' => 'states',
        'cities' => 'cities',
        'country_phone_codes' => 'country_phone_codes',
    ],
    'cache' => [
        'enabled' => true,
        'ttl' => 3600, // 1 hour
    ],
    'seeder' => [
        'truncate_before_seeding' => false,
    ],
];

🗄️ Database Structure

The package creates the following tables:

Countries Table

  • id - Primary key
  • name - Country name
  • iso_code2 - 2-letter ISO code (e.g., US, GB)
  • iso_code3 - 3-letter ISO code (e.g., USA, GBR)
  • num_code - Numeric ISO code
  • status - Active/Inactive status
  • created_at, updated_at - Timestamps
  • deleted_at - Soft delete timestamp

States Table

  • id - Primary key
  • country_id - Foreign key to countries table
  • name - State/Province name
  • status - Active/Inactive status
  • created_at, updated_at - Timestamps
  • deleted_at - Soft delete timestamp

Cities Table

  • id - Primary key
  • state_id - Foreign key to states table
  • name - City name
  • status - Active/Inactive status
  • created_at, updated_at - Timestamps
  • deleted_at - Soft delete timestamp

Country Phone Codes Table

  • id - Primary key
  • phone_code - Country calling code
  • intl_dialing_prefix - International dialing prefix
  • country_id - Foreign key to countries table
  • created_at, updated_at - Timestamps

🧪 Testing

composer test

📝 What's New in v3.0

  • PHP 8.3+ Support - Modern PHP features and performance
  • Laravel 12+ Support - Latest Laravel framework compatibility
  • Modern Migration Syntax - Anonymous classes and improved foreign keys
  • Enhanced Service Class - Useful methods for common operations
  • Proper Type Hints - Better IDE support and code quality
  • Configuration Support - Customizable package settings
  • Improved Namespaces - Better package organization
  • PHPUnit 11 - Latest testing framework

🔄 Upgrading from v1.x

If you're upgrading from version 1.x, please note:

  1. PHP 8.3+ Required - Update your PHP version
  2. Laravel 12+ Required - Update your Laravel version
  3. Model Namespaces Changed - Update any direct model references
  4. Migration Updates - May need to rollback and re-run migrations

See UPGRADE_GUIDE.md for detailed upgrade instructions.

🤝 Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email hello@usamamuneer.me instead of using the issue tracker.

📄 License

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

👨‍💻 Credits

Note: This package is now fully compatible with PHP 8.3+ and Laravel 12+. For older versions, please use v1.x of the package.

usamamuneerchaudhary/country-city-state 适用场景与选型建议

usamamuneerchaudhary/country-city-state 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.68k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2020 年 12 月 27 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 usamamuneerchaudhary/country-city-state 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 24
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-12-27