abe / chinese-regions-for-laravel
中国行政区划
v0.3.0
2024-01-10 19:16 UTC
Requires
- php: ^8.0
- ext-pdo_sqlite: *
- illuminate/console: ^8.0|^9.0|^10.0
- illuminate/contracts: ^8.0|^9.0|^10.0
- illuminate/database: ^8.0|^9.0|^10.0
- illuminate/support: ^8.0|^9.0|^10.0
- spatie/laravel-package-tools: ^1.13
- symfony/process: ^6.0
Requires (Dev)
- larastan/larastan: ^2.0.1
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.0
- orchestra/testbench: ^7.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.5
Suggests
- ext-pdo_sqlite: 使用该扩展解析来自数据源的 SQLite 数据库,只需要在导入数据时开启一次
This package is auto-updated.
Last update: 2024-11-08 11:36:43 UTC
README
数据来源
安装
先决条件
- ext_pdo_sqlite 我们需要读取数据源的 SQLite 文件导入到自己的数据库中,一旦导入完成就可以禁用扩展
然后通过 Composer 安装:
composer require abe/chinese-regions-for-laravel
安装后,运行数据库迁移命令,以创建数据表
php artisan migrate
数据表创建完成后,执行导入命令,导入数据
php artisan chinese-regions:import
使用
我附带了一个简单的实体类, 你也可以自己实现
$chineseRegion = new \Abe\ChineseRegionsForLaravel\ChineseRegion(); /** @var \Illuminate\Database\Eloquent\Collection $provinces */ $provinces = $chineseRegion->provinces; // 所有省份 /** @var \Illuminate\Database\Eloquent\Collection $cities */ $cities = $provinces->first()->cities; // 获取第一个省份的所有城市 /** @var \Illuminate\Database\Eloquent\Collection $areas */ $areas = $cities->first()->areas; // 获取第一个城市的所有区县 /** @var \Illuminate\Database\Eloquent\Collection $streets */ $streets = $areas->first()->streets; // 获取第一个区县的所有街道 /** @var \Illuminate\Database\Eloquent\Collection $villages */ $villages = $streets->first()->towns; // 获取第一个街道的所有乡镇 /** @var \Illuminate\Database\Eloquent\Collection $street */ $street = $villages->parent; // 获取上级 ** @var \Illuminate\Database\Eloquent\Collection $villages */ $villages = $street->children; // 获取**下一级** // 请注意,我们只支持一级下级,平均每个省份有 2 万个村,我不认为有必要返回多级,你可以多次请求接口,或者自行实现
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.