PHPackages                             dileedotdev/laravel-vietnamese-administrative-units - 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. dileedotdev/laravel-vietnamese-administrative-units

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

dileedotdev/laravel-vietnamese-administrative-units
===================================================

A Laravel package for interacting with Vietnamese administrative units

0951[3 PRs](https://github.com/unnoq/laravel-vietnamese-administrative-units/pulls)PHP

Since Jul 3Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/unnoq/laravel-vietnamese-administrative-units)[ Packagist](https://packagist.org/packages/dileedotdev/laravel-vietnamese-administrative-units)[ RSS](/packages/dileedotdev-laravel-vietnamese-administrative-units/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

A Laravel package for interacting with Vietnamese administrative units
======================================================================

[](#a-laravel-package-for-interacting-with-vietnamese-administrative-units)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3d4c45101a9b91c49e90b8f12aedbb3df16d3b8389b969a71d2f5dc947b1dbc5/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f64696c6565646f746465762f6c61726176656c2d766965746e616d6573652d61646d696e6973747261746976652d756e6974732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dileedotdev/laravel-vietnamese-administrative-units)[![GitHub Tests Action Status](https://camo.githubusercontent.com/83afb6a1c19c3121f951fb359ef61fb2650c725d5356a65875301caa904ea282/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64696c6565646f746465762f6c61726176656c2d766965746e616d6573652d61646d696e6973747261746976652d756e6974732f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/dileedotdev/laravel-vietnamese-administrative-units/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/73745902ebda376a683da79b8cb333dcbaf2222945b3f08437e5b97bf822f5cb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f64696c6565646f746465762f6c61726176656c2d766965746e616d6573652d61646d696e6973747261746976652d756e6974732f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/dileedotdev/laravel-vietnamese-administrative-units/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/7de294fd1b28b6b076c026e359c99ca2a18b7b64ed148fbaca33f954d68e68fc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64696c6565646f746465762f6c61726176656c2d766965746e616d6573652d61646d696e6973747261746976652d756e6974732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dileedotdev/laravel-vietnamese-administrative-units)

This package provides a simple way to interact with Vietnamese administrative units in Laravel by normal models and relationships.

[Lasted updated Vietnamese administrative units CSV file was on 13/5/2023](./assets/vietnamese-administrative-units.csv)

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

[](#installation)

You can install the package via composer:

```
composer require dileedotdev/laravel-vietnamese-administrative-units
```

You should publish and run the migrations with:

```
php artisan vendor:publish --tag="vietnamese-administrative-units-migrations"
php artisan migrate
```

You can publish the config file with:

```
php artisan vendor:publish --tag="vietnamese-administrative-units-config"
```

This is the contents of the published config file:

```
return [
    'province' => [
        'model' => \VietnameseAdministrativeUnits\Models\Province::class,
        'table' => 'provinces',
    ],

    'district' => [
        'model' => \VietnameseAdministrativeUnits\Models\District::class,
        'table' => 'districts',
    ],

    'ward' => [
        'model' => \VietnameseAdministrativeUnits\Models\Ward::class,
        'table' => 'wards',
    ],
];
```

Usage
-----

[](#usage)

[![image](./docs/database/schema.excalidraw.png)](./docs/database/schema.excalidraw.png)

As you can see, the package provides 3 models: `Province`, `District`, and `Ward`. Each model uses soft delete. (because in Vietnam, administrative units probably change in the future)

### Import data

[](#import-data)

The first thing you need to do is import administrative units to the database. You can use the command:

```
php artisan vietnamese-administrative-units:import
```

By default, this command will use a CSV file placed in `./assets/vietnamese-administrative-units.csv`. You can change the file using by passing a path to the file as an argument:

```
php artisan vietnamese-administrative-units:import /home/dilee/Downloads/vietnamese-administrative-units.csv
```

If you wonder where the CSV file comes from, you can find it [here](https://www.gso.gov.vn/phuong-phap-luan-thong-ke/danh-muc/don-vi-hanh-chinh/) check on "Quận Huyện, Phường Xã" and click "Xuất Excel" to download the Excel file, next you should manually convert the Excel file to CSV file without changing any data.

### Using models

[](#using-models)

You can use the models as usual:

```
use VietnameseAdministrativeUnits\Models\Ward;

class YourModel {
    public function ward()
    {
        return $this->belongsTo(
            config('vietnamese-administrative-units.ward.model', Ward::class)
        )->withTrashed();
    }
}
```

As I said before, each model uses soft delete, so you should use `withTrashed()` to get a relationship regardless the model is deleted or not.

And don't forget to define a foreign key in your migration:

```
return new class extends Migration
{
    public function up()
    {
        Schema::table('your_table', function (Blueprint $table) {
            $table->foreignId('ward_id')->constrained();
        });
    }
}
```

Below is some useful code:

```
use VietnameseAdministrativeUnits\Models\Province;
use VietnameseAdministrativeUnits\Models\District;
use VietnameseAdministrativeUnits\Models\Ward;

// Get all provinces
Province::all();

// Get all districts
District::all();

// Get all wards
Ward::all();
```

### Can I use the import command many times?

[](#can-i-use-the-import-command-many-times)

Yes, you can. The command is smart enough to check if the administrative unit is already in the database, it will skip that unit and soft delete any unit that is not in the CSV file.

### What I should do if the CSV file I provided is outdated?

[](#what-i-should-do-if-the-csv-file-i-provided-is-outdated)

I will periodically update the CSV file, so rarely you need to update the CSV file yourself. But if the CSV file is outdated, you can follow the below solutions:

Firstly, the command optionally receives the custom path to the CSV file, so you can download the new CSV file and pass it to the command.

Secondly, you can go to the Github repository of this package, create a pull request to update the CSV file, and I will merge it as soon as possible.

Finally, if the above solutions are too complicated for you, easily you can create an issue on Github to ping me to update the CSV file.

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Dileedotdev](https://github.com/dileedotdev)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity26

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

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/47e2161449a748d8324f83eca75917aac149ae95ced37796d72a1da71be7df90?d=identicon)[dileedotdev](/maintainers/dileedotdev)

---

Top Contributors

[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (3 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (3 commits)")[![dileedotdev](https://avatars.githubusercontent.com/u/189419828?v=4)](https://github.com/dileedotdev "dileedotdev (2 commits)")

### Embed Badge

![Health badge](/badges/dileedotdev-laravel-vietnamese-administrative-units/health.svg)

```
[![Health](https://phpackages.com/badges/dileedotdev-laravel-vietnamese-administrative-units/health.svg)](https://phpackages.com/packages/dileedotdev-laravel-vietnamese-administrative-units)
```

###  Alternatives

[sbine/route-viewer

A Laravel Nova tool to view your registered routes.

57215.9k](/packages/sbine-route-viewer)[miracuthbert/laravel-royalty

A user points package for Laravel that can be used to give rewards, loyalty or experience points with real time support

825.1k](/packages/miracuthbert-laravel-royalty)[webidea24/magento2-module-pagebuilder-wysiwyg-html-editor

Magento 2 Module: Make the toggle-Button for HTML Editor available in PageBuilder elements

123.4k](/packages/webidea24-magento2-module-pagebuilder-wysiwyg-html-editor)

PHPackages © 2026

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