Hello everyone, today I would like to share with you the database of administrative units of Vietnam: Province / City, District / District, Ward / Commune for Laravel
This is the first time I have written an article here, it may not be very good, hope you guys understand
Introduce
The day before, I was working on a project to get data about the Vietnamese administrative unit, so I repackaged it as a package for Laravel and shared it with everyone.
Link it here: https://github.com/kjmtrue/vietnam-zone
What this package has:
- Data is extracted directly from the General Statistics Office, so you are assured of accuracy and the data is always updated.
- Quick installation.
- Supports Laravel 5.8 and above.
Setting
Installation through composer:
1 2 | composer require kjmtrue/vietnam-zone |
Copy the config file and migrate
1 2 | php artisan vendor:publish --provider="KjmtrueVietnamZoneServiceProvider" |
If you do not need to customize your database, you can skip this step and through the Data Import section
Database customization
If you want to customize the structure of the database table for your project, do the following:
Rename the table
Open config/vietnam-zone.php
file and change the tables
section:
1 2 3 4 5 6 | <span class="token single-quoted-string string">'tables'</span> <span class="token operator">=</span> <span class="token operator">></span> <span class="token punctuation">[</span> <span class="token single-quoted-string string">'provinces'</span> <span class="token operator">=</span> <span class="token operator">></span> <span class="token single-quoted-string string">'provinces'</span> <span class="token punctuation">,</span> <span class="token single-quoted-string string">'districts'</span> <span class="token operator">=</span> <span class="token operator">></span> <span class="token single-quoted-string string">'districts'</span> <span class="token punctuation">,</span> <span class="token single-quoted-string string">'wards'</span> <span class="token operator">=</span> <span class="token operator">></span> <span class="token single-quoted-string string">'wards'</span> <span class="token punctuation">,</span> <span class="token punctuation">]</span> <span class="token punctuation">,</span> |
Rename the column
Open the config/vietnam-zone.php
file and change the columns
section:
1 2 3 4 5 6 7 | <span class="token single-quoted-string string">'columns'</span> <span class="token operator">=</span> <span class="token operator">></span> <span class="token punctuation">[</span> <span class="token single-quoted-string string">'name'</span> <span class="token operator">=</span> <span class="token operator">></span> <span class="token single-quoted-string string">'name'</span> <span class="token punctuation">,</span> <span class="token single-quoted-string string">'gso_id'</span> <span class="token operator">=</span> <span class="token operator">></span> <span class="token single-quoted-string string">'gso_id'</span> <span class="token punctuation">,</span> <span class="token single-quoted-string string">'province_id'</span> <span class="token operator">=</span> <span class="token operator">></span> <span class="token single-quoted-string string">'province_id'</span> <span class="token punctuation">,</span> <span class="token single-quoted-string string">'district_id'</span> <span class="token operator">=</span> <span class="token operator">></span> <span class="token single-quoted-string string">'district_id'</span> <span class="token punctuation">,</span> <span class="token punctuation">]</span> <span class="token punctuation">,</span> |
Where gso_id
not a random or incremental ID, it is an official boundary code issued under the Government’s Decision No. 124/2004 / QD-TTg of July 8, 2004. This column will be used as a reference for future data updates.
province_id
and district_id
are foreign key columns.
More Collum
Open the following migration files and customize them to your liking:
1 2 3 4 | database/migrations/2020_01_01_000001_create_provinces_table.php database/migrations/2020_01_01_000002_create_districts_table.php database/migrations/2020_01_01_000003_create_wards_table.php |
Import data
Run the migrate command to make the table creation.
1 2 | php artisan migrate |
Finally download and import the data with the following command:
1 2 | php artisan vietnamzone:download |
summary
Above is my share, if you have any questions or requests for me to add to the library, please let me know in the comments below. Those who come over see it, please give me a copy to get the motivation to update.
Thank you for taking the time to support your article!