PHP code example of abe / chinese-regions-for-laravel

1. Go to this page and download the library: Download abe/chinese-regions-for-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abe / chinese-regions-for-laravel example snippets


$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 万个村,我不认为有必要返回多级,你可以多次请求接口,或者自行实现
bash
php artisan migrate