定制 dileedotdev/laravel-vietnamese-administrative-units 二次开发

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

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

dileedotdev/laravel-vietnamese-administrative-units

Composer 安装命令:

composer require dileedotdev/laravel-vietnamese-administrative-units

包简介

A Laravel package for interacting with Vietnamese administrative units

README 文档

README

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

This package provides a simple way to interact with Vietnamese administrative units in Laravel by normal models and relationships.

Lasted updated Vietnamese administrative units CSV file was on 13/5/2023

Installation

You can install the package via composer:

composer require dileedotdev/laravel-vietnamese-administrative-units

You should publish and run the migrations with:

php artisan vendor:publish --tag="vietnamese-administrative-units-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --tag="vietnamese-administrative-units-config"

This is the contents of the published config file:

return [
    'province' => [
        'model' => \VietnameseAdministrativeUnits\Models\Province::class,
        'table' => 'provinces',
    ],

    'district' => [
        'model' => \VietnameseAdministrativeUnits\Models\District::class,
        'table' => 'districts',
    ],

    'ward' => [
        'model' => \VietnameseAdministrativeUnits\Models\Ward::class,
        'table' => 'wards',
    ],
];

Usage

image

As you can see, the package provides 3 models: Province, District, and Ward. Each model uses soft delete. (because in Vietnam, administrative units probably change in the future)

Import data

The first thing you need to do is import administrative units to the database. You can use the command:

php artisan vietnamese-administrative-units:import

By default, this command will use a CSV file placed in ./assets/vietnamese-administrative-units.csv. You can change the file using by passing a path to the file as an argument:

php artisan vietnamese-administrative-units:import /home/dilee/Downloads/vietnamese-administrative-units.csv

If you wonder where the CSV file comes from, you can find it here check on "Quận Huyện, Phường Xã" and click "Xuất Excel" to download the Excel file, next you should manually convert the Excel file to CSV file without changing any data.

Using models

You can use the models as usual:

use VietnameseAdministrativeUnits\Models\Ward;

class YourModel {
    public function ward()
    {
        return $this->belongsTo(
            config('vietnamese-administrative-units.ward.model', Ward::class)
        )->withTrashed();
    }
}

As I said before, each model uses soft delete, so you should use withTrashed() to get a relationship regardless the model is deleted or not.

And don't forget to define a foreign key in your migration:

return new class extends Migration
{
    public function up()
    {
        Schema::table('your_table', function (Blueprint $table) {
            $table->foreignId('ward_id')->constrained();
        });
    }
}

Below is some useful code:

use VietnameseAdministrativeUnits\Models\Province;
use VietnameseAdministrativeUnits\Models\District;
use VietnameseAdministrativeUnits\Models\Ward;

// Get all provinces
Province::all();

// Get all districts
District::all();

// Get all wards
Ward::all();

Can I use the import command many times?

Yes, you can. The command is smart enough to check if the administrative unit is already in the database, it will skip that unit and soft delete any unit that is not in the CSV file.

What I should do if the CSV file I provided is outdated?

I will periodically update the CSV file, so rarely you need to update the CSV file yourself. But if the CSV file is outdated, you can follow the below solutions:

Firstly, the command optionally receives the custom path to the CSV file, so you can download the new CSV file and pass it to the command.

Secondly, you can go to the Github repository of this package, create a pull request to update the CSV file, and I will merge it as soon as possible.

Finally, if the above solutions are too complicated for you, easily you can create an issue on Github to ping me to update the CSV file.

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

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

dileedotdev/laravel-vietnamese-administrative-units 适用场景与选型建议

dileedotdev/laravel-vietnamese-administrative-units 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 96 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 15 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

围绕 dileedotdev/laravel-vietnamese-administrative-units 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-15