hoangphi / vietnam-maps
Vietnam's area database.
Installs: 3 856
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 1
Forks: 15
Open Issues: 0
Requires
- php: ^7.2|^8.0|^8.1
- guzzlehttp/guzzle: ^7.0.1
- illuminate/console: ^5.8|^6|^7|^8|^9|^10
- illuminate/database: ^5.8|^6|^7|^8|^9|^10
- illuminate/support: ^5.8|^6|^7|^8|^9|^10
- maatwebsite/excel: ^3.1
README
Database of Vietnam's area.
Data are taken directly from the General Statistics Office of Vietnam.
Install
composer require hoangphi/vietnam-maps
Extracting
Method 1:
Extract directly via command:
php artisan vietnam-map:install
Method 2:
Copy file config và migration
php artisan vendor:publish --provider="HoangPhi\VietnamMap\VietnamMapServiceProvider"
Customize config và migration
- Rename table
Open file config/vietnam-maps.php
and config:
'tables' => [ 'provinces' => 'provinces', 'districts' => 'districts', 'wards' => 'wards', ],
- Rename column
Open file config/vietnam-maps.php
and config:
'columns' => [ 'name' => 'name', 'gso_id' => 'gso_id', 'province_id' => 'province_id', 'district_id' => 'district_id', ],
- Add column
Open the following migration files and customize if you need:
database/migrations/{datetime}_create_vietnam_maps_table.php
Run migration
php artisan migrate
Download và import into database
php artisan vietnam-map:download
Usage with Models
- Get all provinces, districts, wards
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(); ... } }
- Get data using relationship
use HoangPhi\VietnamMap\Models\Province; class DevController extends Controller { ... public function dev() { $province = Province::first(); $districts = $province->districts; ... } }
- Relation in Province.php
class Province extends Model { ... public function districts() { return $this->hasMany(District::class); } }
- Relation in District.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); } }
- Relation in Ward.php
class Ward extends Model { ... public function district() { return $this->belongsTo(District::class, config('vietnam-maps.columns.district_id'), 'id'); } }
Changelog
Please see CHANGELOG for more information what has changed recently.
Security
If you discover any security-related issues, please email hoangphidev@gmail.com instead of using the issue tracker.
Credits
References
License
The Laravel framework is open-sourced software licensed under the MIT license.