haydenzhou / laravel-china-cities
create cities database with datas imported from Ministry of Civil Affairs of the People's Republic of China
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 0
Forks: 2
Open Issues: 0
pkg:composer/haydenzhou/laravel-china-cities
This package is auto-updated.
Last update: 2025-12-29 03:12:25 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 子城市
待完善...