PHPackages                             wiwichai/thai-address - 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. wiwichai/thai-address

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

wiwichai/thai-address
=====================

A Laravel package for managing Thai addresses. from https://github.com/earthchie/jquery.Thailand.js

v1.0.1(today)01↑2900%MITPHPPHP ^8.2

Since Feb 22Pushed todayCompare

[ Source](https://github.com/wiwichai/thai-address)[ Packagist](https://packagist.org/packages/wiwichai/thai-address)[ RSS](/packages/wiwichai-thai-address/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (2)Versions (3)Used By (0)

🇹🇭 Thai Address
===============

[](#-thai-address)

Laravel Package สำหรับจัดการข้อมูลที่อยู่ไทย (ตำบล / อำเภอ / จังหวัด / รหัสไปรษณีย์) พร้อมรหัสพื้นที่ครบถ้วน

ข้อมูลอ้างอิงจาก [jquery.Thailand.js](https://github.com/earthchie/jquery.Thailand.js) โดย earthchie

---

ความต้องการของระบบ
------------------

[](#ความต้องการของระบบ)

- PHP `^8.2`
- Laravel `^10.0 | ^11.0 | ^12.0 | ^13.0`

---

การติดตั้ง
----------

[](#การติดตั้ง)

```
composer require wiwichai/thai-address
```

---

การใช้งาน
---------

[](#การใช้งาน)

### Import ข้อมูลลง Database

[](#import-ข้อมูลลง-database)

Package มีข้อมูลที่อยู่ไทยมาให้พร้อมแล้ว ไม่ต้องต่อ internet

```
php artisan thai-addresses:install
```

### อัพเดทข้อมูลล่าสุดจาก GitHub

[](#อัพเดทข้อมูลล่าสุดจาก-github)

ใช้เมื่อต้องการดึงข้อมูลใหม่จาก source

```
php artisan thai-addresses:sync
```

---

Commands
--------

[](#commands)

Commandคำอธิบาย`thai-addresses:install`Import ข้อมูลจาก JSON ที่มาพร้อม package เข้า DB (ไม่ต้องต่อ internet)`thai-addresses:sync`ดึงข้อมูลล่าสุดจาก GitHub → บันทึก JSON → import ลง DB### Options

[](#options)

```
# ดูตัวอย่างข้อมูลก่อน import จริง
php artisan thai-addresses:install --dry-run
php artisan thai-addresses:sync --dry-run
```

---

Models
------

[](#models)

### `ThaiAddress`

[](#thaiaddress)

ใช้สำหรับค้นหาข้อมูลที่อยู่ไทย

```
use Wichai\ThaiAddress\Models\ThaiAddress;

// ค้นหาตำบล
ThaiAddress::where('subdistrict', 'like', '%ลาดยาว%')->get();

// ค้นหาตามจังหวัด
ThaiAddress::where('province', 'กรุงเทพมหานคร')->get();

// ค้นหาตามรหัสไปรษณีย์
ThaiAddress::where('postal_code', '10900')->get();

// ค้นหาตามรหัสอำเภอ
ThaiAddress::where('district_code', '1001')->get();
```

### `Address`

[](#address)

ใช้สำหรับบันทึกที่อยู่ของ Model ต่างๆ ในระบบ รองรับ Polymorphic Relationship

```
use Wichai\ThaiAddress\Models\Address;

// สร้างที่อยู่ใหม่
Address::create([
    'addressable_type' => 'App\Models\User',
    'addressable_id'   => 1,
    'label'            => 'บ้าน',
    'address'          => '123',
    'moo'              => '7',
    'road'             => 'สุขุมวิท',
    'subdistrict'      => 'คลองเตย',
    'district'         => 'คลองเตย',
    'province'         => 'กรุงเทพมหานคร',
    'postal_code'      => '10110',
    'contact_phone'    => '0812345678',
]);
```

---

Trait `HasAddresses`
--------------------

[](#trait-hasaddresses)

ใช้กับ Model ใดก็ได้ที่ต้องการเก็บข้อมูลที่อยู่ เช่น `User`, `Customer`, `Shop`

### 1. เพิ่ม Trait เข้า Model

[](#1-เพิ่ม-trait-เข้า-model)

```
use Wichai\ThaiAddress\Traits\HasAddresses;

class User extends Authenticatable
{
    use HasAddresses;
}
```

### 2. ใช้งาน

[](#2-ใช้งาน)

```
$user = User::find(1);

// ดึงที่อยู่ทั้งหมดของ user
$user->addresses;

// เพิ่มที่อยู่ใหม่
$user->addresses()->create([
    'label'         => 'บ้าน',
    'address'       => '123',
    'moo'           => '7',
    'road'          => 'สุขุมวิท',
    'subdistrict'   => 'คลองเตย',
    'district'      => 'คลองเตย',
    'province'      => 'กรุงเทพมหานคร',
    'postal_code'   => '10110',
    'contact_phone' => '0812345678',
]);

// ดึงที่อยู่แรก
$user->addresses()->first();

// ค้นหาที่อยู่ตาม label
$user->addresses()->where('label', 'บ้าน')->first();
```

---

โครงสร้างตาราง
--------------

[](#โครงสร้างตาราง)

### `thai_addresses`

[](#thai_addresses)

ColumnTypeคำอธิบาย`id`bigintPrimary key`subdistrict_code`stringรหัสตำบล`subdistrict`stringชื่อตำบล / แขวง`district_code`stringรหัสอำเภอ`district`stringชื่ออำเภอ / เขต`province_code`stringรหัสจังหวัด`province`stringชื่อจังหวัด`postal_code`stringรหัสไปรษณีย์`created_at`timestamp`updated_at`timestamp`deleted_at`timestampSoft delete### `addresses`

[](#addresses)

ColumnTypeคำอธิบาย`id`bigintPrimary key`addressable_type`stringชื่อ Model ที่เชื่อมอยู่`addressable_id`bigintID ของ Model ที่เชื่อมอยู่`label`stringชื่อที่อยู่ เช่น บ้าน, ที่ทำงาน`address`stringบ้านเลขที่`moo`stringหมู่ที่`road`stringถนน`subdistrict`stringตำบล / แขวง`district`stringอำเภอ / เขต`province`stringจังหวัด`postal_code`stringรหัสไปรษณีย์`contact_phone`stringเบอร์โทรติดต่อ`created_at`timestamp`updated_at`timestamp---

แหล่งที่มาของข้อมูล
-------------------

[](#แหล่งที่มาของข้อมูล)

ข้อมูลที่อยู่ไทยได้รับมาจาก [jquery.Thailand.js](https://github.com/earthchie/jquery.Thailand.js) ซึ่งอ้างอิงจากฐานข้อมูลของไปรษณีย์ไทย

---

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance100

Actively maintained with recent releases

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

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 ~111 days

Total

2

Last Release

0d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/33937979?v=4)[Wichai Wimonkhachonyot](/maintainers/wiwichai)[@wiwichai](https://github.com/wiwichai)

---

Tags

addresslaravelthai-addressthailandlaraveladdressthaithailand

### Embed Badge

![Health badge](/badges/wiwichai-thai-address/health.svg)

```
[![Health](https://phpackages.com/badges/wiwichai-thai-address/health.svg)](https://phpackages.com/packages/wiwichai-thai-address)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[zidbih/laravel-deadlock

Make temporary Laravel workarounds expire and fail CI when ignored.

954.0k](/packages/zidbih-laravel-deadlock)

PHPackages © 2026

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