ethantechnology/laravel-jp-postal-codes
Composer 安装命令:
composer require ethantechnology/laravel-jp-postal-codes
包简介
Laravel package for Japanese prefectures and postal codes
README 文档
README
Laravel package for Japanese prefectures and postal codes. The data is imported from the official Japan Post service.
Requirements
- PHP 7.4 or higher
- Laravel 7.0 or higher
Installation
composer require ethantechnology/laravel-jp-postal-codes
Service Provider Registration
For Laravel 5.5+
If you're using Laravel 5.5 or higher, the package will automatically register its service provider thanks to Laravel's package discovery feature.
For Laravel 5.4 and below
If you're using Laravel 5.4 or below, you need to manually register the service provider. Add the following line to the providers array in your config/app.php file:
Eta\JpPostalCodes\JpPostalCodesServiceProvider::class,
Configuration
To customize the table names and other settings, publish the configuration file:
php artisan vendor:publish --tag=jp-postal-codes-config
This will create a config/jp-postal-codes.php file where you can:
- Change the table names for prefectures, cities, and postal codes
- Modify the URL for downloading postal code data
- Adjust import settings like chunk size
Customizing Migrations
Since we no longer automatically load migrations, you need to publish them first:
php artisan vendor:publish --tag=jp-postal-codes-migrations
After publishing, you can find and modify the migration files in your database/migrations directory. You should customize them before running migrations if you:
- Changed table names in the config
- Need to adjust table structures (add or modify columns)
- Want to change indexes or foreign key constraints
Important: Make sure your migration table names match those in the config file. If you change table names in the config, update the corresponding migration files before running migrations.
Migration
After installing and configuring, run:
php artisan migrate
This will create the following tables:
prefectures: Contains all Japanese prefectures (or your custom table name if configured)cities: Contains all Japanese cities/municipalities (or your custom table name if configured)postal_codes: Contains Japanese postal codes with their corresponding prefectures and cities (or your custom table name if configured)
Updating Postal Code Data
To download and update all data from the official Japan Post service:
php artisan jp-postal-codes:update
This command will:
- Download the latest postal code data from Japan Post
- Clean all existing data in the tables
- Import the postal codes
- Automatically extract and create prefectures and cities from the postal code data
Note: This process downloads data from the official Japan Post service and might take some time to complete. The data is provided in Shift-JIS encoding and will be automatically converted to UTF-8 during import.
Usage
use Eta\JpPostalCodes\Models\Prefecture; use Eta\JpPostalCodes\Models\City; use Eta\JpPostalCodes\Models\PostalCode; // Get all prefectures $prefectures = Prefecture::all(); // Find prefecture by ID $tokyo = Prefecture::find(13); // Get all cities in a prefecture $tokyoCities = $tokyo->cities; // Find city by ID $city = City::find('13104'); // Get the prefecture for a city $prefecture = $city->prefecture; // Find location by postal code $locations = PostalCode::where('postal_code', '1600022')->get(); // Or using the scope $locations = PostalCode::postal('1600022')->get(); // Get the city and prefecture for a postal code $location = PostalCode::postal('1600022')->first(); $city = $location->city; $prefecture = $location->prefecture;
Custom Table Names
After publishing the config file, you can modify the table names:
// config/jp-postal-codes.php return [ 'tables' => [ 'prefectures' => 'custom_prefectures', 'cities' => 'custom_cities', 'postal_codes' => 'custom_postal_codes', ], // ... ];
Make sure to update your migration files to match these table names before running migrations.
License
MIT
ethantechnology/laravel-jp-postal-codes 适用场景与选型建议
ethantechnology/laravel-jp-postal-codes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 203 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 07 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「japanese」 「japan」 「addresses」 「regions」 「postal codes」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ethantechnology/laravel-jp-postal-codes 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ethantechnology/laravel-jp-postal-codes 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ethantechnology/laravel-jp-postal-codes 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Translate comments in laravel/laravel 5.* project to Japanese
Japanese MyNumber (Individual Number / Corporate Number) verifier
Faker Japanese is a Faker provider that generates fake Japanese related data for you.
Square Payments integration with Magento 2
Translate your Japanese into Kansai dialect.
This library 'php-jp-customer-barcode-generator' is an easy to use, framework independent, Japan post's customer barcode generator in PHP.
统计信息
- 总下载量: 203
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 29
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-24