ajangsupardi/laravel-kodepos
Composer 安装命令:
composer require ajangsupardi/laravel-kodepos
包简介
Laravel package for seeding Indonesian address data (provinces, regencies, districts, villages) with postal codes from Pos Indonesia
README 文档
README
Laravel package for downloading and seeding Indonesian address data (provinces, regencies, districts, villages) with postal codes from the official Pos Indonesia website.
Features
- Auto-download kodepos data from Pos Indonesia
- Hierarchical data parsing: Province → Regency → District → Village
- Ready-to-use database seeders
- Migration files included
- Configurable and extendable Eloquent models
- Supports Laravel 11, 12, and 13
Installation
composer require ajangsupardi/laravel-kodepos
Publish Configuration (optional)
php artisan vendor:publish --tag=kodepos-config
Publish Migrations (optional)
php artisan vendor:publish --tag=kodepos-migrations
Note: Migrations are automatically loaded by the service provider, so publishing is only needed if you want to modify the table structure.
Usage
1. Download Kodepos Data
php artisan kodepos:download
This command will download all kodepos data from Pos Indonesia and save it as a CSV file.
2. Run the Seeder
php artisan db:seed --class=Ajangsupardi\Kodepos\Database\Seeders\KodeposSeeder
Or add it to your DatabaseSeeder.php:
use Ajangsupardi\Kodepos\Database\Seeders\KodeposSeeder; public function run(): void { $this->call([ KodeposSeeder::class, ]); }
3. Auto-download & Seed
If you want to combine download and seed in a single step, you can call the download command before the seeder:
use Illuminate\Support\Facades\Artisan; $storagePath = config('kodepos.storage_path'); if (! file_exists($storagePath.'/kodepos.csv')) { Artisan::call('kodepos:download'); }
Database Tables
This package creates 4 tables:
| Table | Description |
|---|---|
provinces |
Province data (id, name, code) |
regencies |
Regency/city data (id, province_id, name) |
districts |
District/sub-district data (id, regency_id, name) |
villages |
Village data (id, district_id, name, postal_code) |
Configuration
Edit config/kodepos.php:
return [ // CSV file storage path 'storage_path' => storage_path('app/kodepos'), // Database table prefix (null = no prefix) 'table_prefix' => null, // Custom models 'models' => [ 'province' => Ajangsupardi\Kodepos\Models\Province::class, 'regency' => Ajangsupardi\Kodepos\Models\Regency::class, 'district' => Ajangsupardi\Kodepos\Models\District::class, 'village' => Ajangsupardi\Kodepos\Models\Village::class, ], // HTTP client settings 'http' => [ 'timeout' => 60, 'connect_timeout' => 10, 'retry' => 3, 'retry_delay' => 1000, 'user_agent' => 'Mozilla/5.0 (compatible; LaravelKodepos/1.0)', ], ];
Custom Models
You can extend the default models to add columns or relationships:
namespace App\Models; use Ajangsupardi\Kodepos\Models\Province as BaseProvince; class Province extends BaseProvince { protected $fillable = ['name', 'code', 'your_custom_field']; // Add custom relationships or methods }
Then update the configuration:
'models' => [ 'province' => App\Models\Province::class, ],
Table Prefix
If you want to use a prefix for your tables:
'table_prefix' => 'kodepos_',
This will create tables: kodepos_provinces, kodepos_regencies, kodepos_districts, kodepos_villages.
Example Queries
use Ajangsupardi\Kodepos\Models\Province; use Ajangsupardi\Kodepos\Models\Village; // Get all provinces $provinces = Province::all(); // Get regencies in East Java $regencies = Province::where('name', 'Jawa Timur') ->first() ->regencies; // Find a village by postal code $village = Village::where('postal_code', '60111')->first(); // Get full address hierarchy from village to province $village = Village::with('district.regency.province') ->where('postal_code', '60111') ->first();
Requirements
- PHP ^8.2
- Laravel ^11.0 / ^12.0 / ^13.0
License
MIT License. See LICENSE for more information.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-19