haydenzhou / laravel-china-cities
There is no license information available for the latest version (v1.0.0) of this package.
create cities database with datas imported from Ministry of Civil Affairs of the People's Republic of China
v1.0.0
2019-04-03 03:10 UTC
This package is auto-updated.
Last update: 2025-08-29 02:06:06 UTC
README
feature
- 根据中华人民共和国民政部的提供的行政区划代码 创建项目的城市表 http://www.mca.gov.cn/article/sj/xzqh/2019/
- 提供一些封装的方法
使用
发布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 子城市
待完善...