zmap95/vietnam-maps 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

zmap95/vietnam-maps

最新稳定版本:v1.0.4

Composer 安装命令:

composer require zmap95/vietnam-maps

包简介

Vietnam's area database.

README 文档

README

Database of Vietnam's area.

Data are taken directly from the General Statistics Office of Vietnam.

Latest Version on Packagist Total Downloads

Install

composer require zmap95/vietnam-maps

Extracting

Method 1:

Extract directly via command:

php artisan vietnam-map:install

Method 2:

Copy file config và migration

php artisan vendor:publish --provider="Zmap95\VietnamMap\VietnamMapServiceProvider"

Customize config và migration

  1. Rename table

Open file config/vietnam-maps.php and config:

'tables' => [
    'provinces' => 'provinces',
    'districts' => 'districts',
    'wards'     => 'wards',
],
  1. Rename column

Open file config/vietnam-maps.php and config:

'columns' => [
    'name'        => 'name',
    'gso_id'      => 'gso_id',
    'province_id' => 'province_id',
    'district_id' => 'district_id',
],
  1. Add column

Open the following migration files and customize if you need:

database/migrations/{datetime}_create_vietnam_maps_table.php

Run migration

php artisan migrate

Download và import into database

php artisan vietnam-map:download

Usage with Models

  1. Get all provinces, districts, wards
    use Zmap95\VietnamMap\Models\Province;
    use Zmap95\VietnamMap\Models\District;
    use Zmap95\VietnamMap\Models\Ward;

   class DevController extends Controller
   {
       ...
       public function dev()
       {
           $provinces = Province::all();
           $districts = District::all();
           $wards = Ward::all();
           ...
       }
   }
  1. Get data using relationship
    use zmap95\VietnamMap\Models\Province;

   class DevController extends Controller
   {
       ...
       public function dev()
       {
           $province = Province::first();
           $districts = $province->districts;
           ...
       }
   }
  1. Relation in Province.php
    class Province extends Model
    {
        ...
        public function districts()
        {
            return $this->hasMany(District::class);
        }
    }
  1. Relation in District.php
    class District extends Model
    {
        ...
        public function province()
        {
            return $this->belongsTo(Province::class, config('vietnam-maps.columns.province_id'), 'id');
        }
        
        public function wards()
        {
            return $this->hasMany(Ward::class);
        }
    }
  1. Relation in Ward.php
    class Ward extends Model
    {
        ...
        public function district()
        {
            return $this->belongsTo(District::class, config('vietnam-maps.columns.district_id'), 'id');
        }
    }

Changelog

Please see CHANGELOG for more information what has changed recently.

References

  1. General Statistics Office of Vietnam
  2. Vietnam Zone

License

The Laravel framework is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-18