PHPackages                             simplecms/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. simplecms/region

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

simplecms/region
================

SimpleCMS/Laravel Region Component / 中国行政地理划分组件

1.1.1(1y ago)060MITPHPPHP ^8.2

Since Jun 16Pushed 1y ago1 watchersCompare

[ Source](https://github.com/hackout/simplecms-region)[ Packagist](https://packagist.org/packages/simplecms/region)[ RSS](/packages/simplecms-region/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (12)Used By (0)

SimpleCMS/Laravel Region Component
==================================

[](#simplecmslaravel-region-component)

📦 A SimpleCMS/Laravel component for Chinese national geographic information based on information published by the National Bureau of Statistics.

English | [简体中文](./README_zhCN.md)

[![Latest Stable Version](https://camo.githubusercontent.com/0cd105fe162d24c22311c5068c5c54fc4be19812b8bb3bde2c0f34d8015ad779/68747470733a2f2f706f7365722e707567782e6f72672f73696d706c65636d732f726567696f6e2f762f737461626c652e737667)](https://packagist.org/packages/simplecms/region) [![Latest Unstable Version](https://camo.githubusercontent.com/2ec0e896dc49ccc61272e44a114b4dec5d6b1bc3e63c3f2b8d0222a888e1a0b1/68747470733a2f2f706f7365722e707567782e6f72672f73696d706c65636d732f726567696f6e2f762f756e737461626c652e737667)](https://packagist.org/packages/simplecms/region) [![Code Coverage](https://camo.githubusercontent.com/2ee8f0077642b1aa146386a539770cf2e2511f775b86b3c1122c447d4571565f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6f766572747275652f656173792d736d732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/hackout/simplecms-region/?branch=master) [![Total Downloads](https://camo.githubusercontent.com/8b2ac14116f970753928d3217b524a8e3a58b395e47ef514aa87a9474ed6779e/68747470733a2f2f706f7365722e707567782e6f72672f73696d706c65636d732f726567696f6e2f646f776e6c6f616473)](https://packagist.org/packages/simplecms/region) [![License](https://camo.githubusercontent.com/29d30d3b1ebfb5d6a0666a83ec035896e103d3a6fb28d56c628d66cd69aa629e/68747470733a2f2f706f7365722e707567782e6f72672f73696d706c65636d732f726567696f6e2f6c6963656e7365)](https://packagist.org/packages/simplecms/region)

Requirements
------------

[](#requirements)

- PHP &gt;= 8.2
- MySql &gt;= 8.0
- [Laravel/Framework](https://packagist.org/packages/laravel/framework) &gt;= 11.0

Installation
------------

[](#installation)

```
composer require simplecms/region
```

Usage
-----

[](#usage)

Includes a distance method.

### Model Usage

[](#model-usage)

Use `RegionTrait` to associate with the model.

```
use \SimpleCMS\Region\Traits\RegionTrait;
```

The model will automatically associate with the `region` morphMany relationship

#### SCOPE

[](#scope)

Query model attributes values

```
$query->withGeoDistance(23.9999,133.9999,10000);
```

### Facade

[](#facade)

```
use SimpleCMS\Region\Facades\Region;

Region::getAll(); // Returns the complete list
Region::findRegion(string $code = 'Administrative Identifier'); // Query geographic information
Region::getAllChildren(string $code = 'Administrative Identifier'); // Query all children
Region::getChildren(string $code, int $deep = 0); // Query down with depth
Region::checkName(string $name); // Check name validity
Region::checkCode(string $code); // Check validity of administrative code
Region::checkArea(string $area); // Check area code validity
Region::checkNumber(string $number); // Check phone number validity
Region::checkZip(string $zip); // Check zip code validity supports full zip code
```

### Laravel Model Casts

[](#laravel-model-casts)

```
use SimpleCMS\Region\Casts\Point;
use SimpleCMS\Region\Casts\LineString;
use SimpleCMS\Region\Casts\Polygon;

public $casts = [
    'geo' => Point::class,
    'geo' => LineString::class,
    'geo' => Polygon::class
];
```

### Helpers

[](#helpers)

```
distance($lat1,$lng1,$lat2,$lng2); // Calculate distance between two locations
```

### Validation

[](#validation)

```
$rules = [
    'region' => 'region_code', // Check administrative code
    'region_name' => 'region_name', // Check geographic name
    'region_zip' => 'region_zip', // Check zip code
    'region_area' => 'region_area', // Check area code
    'region_number' => 'region_number', // Check phone number (landline with area code)
];
$messages = [
    'region.region_code' => 'Incorrect administrative code',
    'region_name.region_name' => 'Incorrect geographic name',
    'region_zip.region_zip' => 'Incorrect zip code',
    'region_area.region_area' => 'Incorrect area code',
    'region_number.region_number' => 'Incorrect area code',
];
$data = $request->validate($rules,$messages);
```

Custom Geographic Data
----------------------

[](#custom-geographic-data)

You can customize your own data using the `.env` file.

### Modify Configuration File Path

[](#modify-configuration-file-path)

Add the following code to the `.env` file:

```
BANK_PATH='Your Geographic JSON file address' #Absolute location
```

### JSON Data Format

[](#json-data-format)

The data structure should follow the format below:

```
{
    "name": "Name",
    "short": "Abbreviation/Short Name",
    "code": "Unique Geographic Identifier",
    "area": "Area Code",
    "zip": "Postal Code",
    "lng": 100.00000, #Longitude
    "lat": 32.00000, #Latitude
    "children": [
        ....#Same structure as above
    ]
}
```

SimpleCMS Extension
-------------------

[](#simplecms-extension)

Please load `simplecms/framework` first.

### Service Calls

[](#service-calls)

```
use SimpleService;
// Get distance
$service->selectDistance(float $lat = 23.23211, float $lng = 111.23123,string $column = 'location');
// Query by record
$service->queryDistance(float $lat = 23.23211, float $lng = 111.23123, float $maxDistance = 50,string $column = 'location')
```

License
-------

[](#license)

MIT

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~4 days

Total

10

Last Release

660d ago

PHP version history (2 changes)1.0.1PHP &gt;=8.0

1.0.7PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![hackout](https://avatars.githubusercontent.com/u/9741288?v=4)](https://github.com/hackout "hackout (74 commits)")

---

Tags

laravelregionSimpleCMS

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/simplecms-region/health.svg)

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

###  Alternatives

[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[gehrisandro/tailwind-merge-laravel

TailwindMerge for Laravel merges multiple Tailwind CSS classes by automatically resolving conflicts between them

341682.2k18](/packages/gehrisandro-tailwind-merge-laravel)[nickurt/laravel-akismet

Akismet for Laravel 11.x/12.x/13.x

97139.6k2](/packages/nickurt-laravel-akismet)[whitecube/laravel-timezones

Store UTC dates in the database and work with custom timezones in the application.

106106.2k](/packages/whitecube-laravel-timezones)[forxer/laravel-gravatar

A library providing easy gravatar integration in a Laravel project.

4235.6k](/packages/forxer-laravel-gravatar)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)

PHPackages © 2026

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