定制 ethantechnology/laravel-jp-postal-codes 二次开发

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

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

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:

  1. Changed table names in the config
  2. Need to adjust table structures (add or modify columns)
  3. 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:

  1. Download the latest postal code data from Japan Post
  2. Clean all existing data in the tables
  3. Import the postal codes
  4. 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 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-07-24