Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hoangphidev/vietnam-maps
đ Laravel database of Vietnam's area.
https://github.com/hoangphidev/vietnam-maps
database general-statistics-office laravel-package php vietnam vietnam-area vietnam-database vietnam-maps
Last synced: 4 days ago
JSON representation
đ Laravel database of Vietnam's area.
- Host: GitHub
- URL: https://github.com/hoangphidev/vietnam-maps
- Owner: hoangphidev
- License: mit
- Created: 2020-11-22T06:10:24.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-20T07:36:24.000Z (11 months ago)
- Last Synced: 2024-09-22T22:17:54.635Z (about 2 months ago)
- Topics: database, general-statistics-office, laravel-package, php, vietnam, vietnam-area, vietnam-database, vietnam-maps
- Language: PHP
- Homepage:
- Size: 667 KB
- Stars: 13
- Watchers: 1
- Forks: 15
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## Vietnam Maps
Database of Vietnam's area.
Data are taken directly from the General Statistics Office of Vietnam.
[![Latest Version on Packagist](https://img.shields.io/packagist/v/hoangphi/vietnam-maps.svg?style=flat-square)](https://packagist.org/packages/hoangphi/vietnam-maps)
[![Total Downloads](https://img.shields.io/packagist/dt/hoangphi/vietnam-maps.svg?style=flat-square)](https://packagist.org/packages/hoangphi/vietnam-maps)## Install
```shell
composer require hoangphi/vietnam-maps
```## Extracting
### Method 1:
Extract directly via command:
```shell
php artisan vietnam-map:install
```### Method 2:
#### Copy file config vĂ migration
```shell
php artisan vendor:publish --provider="HoangPhi\VietnamMap\VietnamMapServiceProvider"
```#### Customize config vĂ migration
1. Rename table
Open file `config/vietnam-maps.php` and config:
```php
'tables' => [
'provinces' => 'provinces',
'districts' => 'districts',
'wards' => 'wards',
],
```2. Rename column
Open file `config/vietnam-maps.php` and config:
```php
'columns' => [
'name' => 'name',
'gso_id' => 'gso_id',
'province_id' => 'province_id',
'district_id' => 'district_id',
],
```3. Add column
Open the following migration files and customize if you need:
```shell
database/migrations/{datetime}_create_vietnam_maps_table.php
```#### Run migration
```shell
php artisan migrate
```#### Download vĂ import into database
```shell
php artisan vietnam-map:download
```## Usage with Models
1. Get all provinces, districts, wards
```php
use HoangPhi\VietnamMap\Models\Province;
use HoangPhi\VietnamMap\Models\District;
use HoangPhi\VietnamMap\Models\Ward;class DevController extends Controller
{
...
public function dev()
{
$provinces = Province::all();
$districts = District::all();
$wards = Ward::all();
...
}
}
```2. Get data using relationship
```php
use HoangPhi\VietnamMap\Models\Province;class DevController extends Controller
{
...
public function dev()
{
$province = Province::first();
$districts = $province->districts;
...
}
}
```
3. Relation in Province.php```php
class Province extends Model
{
...
public function districts()
{
return $this->hasMany(District::class);
}
}
```4. Relation in District.php
```php
class District extends Model
{
...
public function province()
{
return $this->belongsTo(Province::class, config('vietnam-maps.columns.province_id'), 'id');
}
public function wards()
{
return $this->hasMany(Ward::class);
}
}
```5. Relation in Ward.php
```php
class Ward extends Model
{
...
public function district()
{
return $this->belongsTo(District::class, config('vietnam-maps.columns.district_id'), 'id');
}
}
```## Changelog
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
## Security
If you discover any security-related issues, please email [[email protected]](mailto:[email protected]) instead of using the issue tracker.
## Credits
- [Phi Hoang](https://github.com/hoangphidev)
- [All Contributors](../../contributors)## References
1. [General Statistics Office of Vietnam](https://www.gso.gov.vn/dmhc2015)
2. [Vietnam Zone](https://github.com/kjmtrue/vietnam-zone)## License
The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).