Skip to content

create cities database with datas imported from Ministry of Civil Affairs of the People's Republic of China

Notifications You must be signed in to change notification settings

haydenzhourepo/laravel-china-cities

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

中国城市区划

feature

  1. 根据中华人民共和国民政部的提供的行政区划代码 创建项目的城市表 http://www.mca.gov.cn/article/sj/xzqh/2019/
  2. 提供一些封装的方法

使用

发布migration文件 并填充数据

artisan vendor:publish --provider="HaydenZhou\LaravelChinaCities\LaravelChinaCitiesServiceProvider"
php artisan migrate

php artisan city:seed

创建City model

php artisan make:model City -c

City model 中 使用 CityTrait

namespace App;

use Illuminate\Database\Eloquent\Model;
use HaydenZhou\LaravelChinaCities\CityTrait;

class City extends Model
{
    use CityTrait;

    public $timestamps = false;

    protected $primaryKey = 'code';

    protected $fillable = ['code', 'name', 'parent_code'];

    public function getRouteKeyName()
    {
        return 'code';
    }
    
}

trait 方法

parent 父级城市

children 子城市

待完善...

About

create cities database with datas imported from Ministry of Civil Affairs of the People's Republic of China

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages