PHPackages                             lvqingan/laravel-cn-region - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lvqingan/laravel-cn-region

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

lvqingan/laravel-cn-region
==========================

Laravel中国省市区无数据库实现方案

15PHP

Since May 5Pushed 7y ago1 watchersCompare

[ Source](https://github.com/lvqingan/laravel-cn-region)[ Packagist](https://packagist.org/packages/lvqingan/laravel-cn-region)[ RSS](/packages/lvqingan-laravel-cn-region/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

### 中国行政区划省市区（无数据表实现方案）

[](#中国行政区划省市区无数据表实现方案)

思路：通过身份证前6位来处理省市区的级联关系

[![Build Status](https://camo.githubusercontent.com/df8037ffe42b97a8b922f2ae74bbff509abc7a5bbba7e77544aa38f3c7effc24/68747470733a2f2f6170692e7472617669732d63692e6f72672f6c7671696e67616e2f6c61726176656c2d636e2d726567696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/lvqingan/laravel-cn-region) [![Style Status](https://camo.githubusercontent.com/5486943396814b6ccc335ab467b590587e7988cea5bcaffa2a12c1304a851e85/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3138333937343433322f736869656c643f7374796c653d706c6173746963)](https://github.styleci.io/repos/183974432)

#### 安装

[](#安装)

1. 安装代码库

```
composer require lvqingan/laravel-cn-region:dev-master
```

2. 修改 `database/migration` 中的表结构，增加保存区域的字段（默认使用`region`）

```
$table->char('region', 6);
$table->index(['region']);
```

3. 在 `Eloquent` 的模型中添加 `HasRegion` trait

> 默认使用 `region` 作为字段名，如果数据表使用的是其他字段来保存区域值，则需要定义属性 `$regionFieldName`

```
   class User extends Model
   {
       use HasRegion;
   }
```

```
   class User extends Model
   {
       use HasRegion;

       protected $regionFieldName = 'shengshiqu';
   }
```

#### 获取下拉列表数据

[](#获取下拉列表数据)

**省份**

```
$provinces = (new \Lvqingan\Region\Loader('province'))->load();
```

```
{
    "110000":"北京市",
    "820000":"澳门特别行政区"
}
```

**城市**

```
$cities = (new \Lvqingan\Region\Loader('city', '340000'))->load();
```

```
{
    "340100":"合肥市",
    "341800":"宣城市"
}
```

**区县**

```
$districts = (new \Lvqingan\Region\Loader('340100', '340100'))->load();
```

```
{
    "340103":"庐阳区",
    "340111":"包河区"
}
```

#### 获取名称

[](#获取名称)

实例化的模型对象可以调用下面的属性（假设区域值为340104）

属性名称说明返回值province\_code省份编码340000city\_code城市编码340100district\_code区县编码340104province\_name省份名称安徽省city\_name城市名称合肥市district\_name区县名称蜀山区full\_city\_name完整城市名称安徽省合肥市full\_district\_name完整区县名称安徽省合肥市蜀山区#### 数据查询

[](#数据查询)

按区域编码直接查询区域等于该值的数据

```
    User::whereRegion('340104')->get()
```

按区域编码直接查询区域包含在该范围内的数据

```
    User::whereInRegion('340000')->get()
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity5

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a518cd6e6545ebba32191dbbf21393ceba6fc205895c9541f67c0b58761fb338?d=identicon)[lvqingan](/maintainers/lvqingan)

---

Top Contributors

[![lvqingan](https://avatars.githubusercontent.com/u/2076441?v=4)](https://github.com/lvqingan "lvqingan (18 commits)")

### Embed Badge

![Health badge](/badges/lvqingan-laravel-cn-region/health.svg)

```
[![Health](https://phpackages.com/badges/lvqingan-laravel-cn-region/health.svg)](https://phpackages.com/packages/lvqingan-laravel-cn-region)
```

###  Alternatives

[alexsabur/orchid-editorjs-field

A orchid editorjs field

1327.4k](/packages/alexsabur-orchid-editorjs-field)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
