zaidysf / idn-area-laravel
Clean Indonesian Area Data Package for Laravel - Provinces, Regencies, Districts, Villages with curated official data
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 2
pkg:composer/zaidysf/idn-area-laravel
Requires
- php: ^8.1|^8.2|^8.3|^8.4
- illuminate/contracts: ^10.0|^11.0|^12.0
- illuminate/database: ^10.0|^11.0|^12.0
- illuminate/support: ^10.0|^11.0|^12.0
- spatie/laravel-package-tools: ^1.13.0|^1.14.0|^1.15.0|^1.16.0
Requires (Dev)
- fakerphp/faker: ^1.21|^1.23|^1.24
- larastan/larastan: ^2.9|^3.0
- laravel/pint: ^1.0|^2.0
- mockery/mockery: ^1.4|^1.6|^1.7
- nunomaduro/collision: ^7.0|^8.0|^9.0
- orchestra/testbench: ^8.0|^9.0|^10.0
- pestphp/pest: ^2.0|^3.0
- pestphp/pest-plugin-arch: ^2.0|^3.0
- pestphp/pest-plugin-laravel: ^2.4|^3.0
- pestphp/pest-plugin-type-coverage: ^2.8|^3.0
- phpstan/extension-installer: ^1.1|^1.3|^1.4
- phpstan/phpstan-deprecation-rules: ^1.0|^1.1|^1.2
- phpstan/phpstan-phpunit: ^1.0|^1.3|^1.4
This package is auto-updated.
Last update: 2025-10-18 02:35:53 UTC
README
Clean and fast Indonesian administrative area data package for Laravel. Get provinces, regencies, districts, and villages with curated official data.
โจ Features
- ๐ API Mode (Recommended) - Always up-to-date data via DataToko service
- ๐ Fast Local Mode - No API calls, works offline
- ๐งน Clean Data - Curated and validated from official sources
- ๐ Search & Filter - Advanced search capabilities
- ๐ฆ Easy Setup - Simple artisan commands
- โ Laravel 10/11/12 - Full compatibility
- ๐งช 100% Tested - 186 passing tests
๐ Data Coverage
Type | Count | Source |
---|---|---|
Provinces | 38 | Official Indonesian Government |
Regencies | 514+ | Curated from BPS Data |
Districts | 7,292+ | Updated Regularly |
Villages | 84,345+ | Complete Coverage |
๐ Installation
composer require zaidysf/idn-area-laravel
โก Quick Setup
๐ API Mode (Recommended)
Get always up-to-date data directly from official sources via DataToko service:
# Setup with API mode for real-time data
php artisan idn-area:setup --mode=api
Why API Mode?
- โ Always Current - Real-time data from official government sources
- โ No Maintenance - We handle all data updates automatically
- โ Accurate - Direct from BPS (Indonesian Central Statistics Agency)
- โ Reliable - Enterprise-grade DataToko infrastructure
๐ Local Mode (Offline)
For applications that need offline capability:
# Setup with local mode (uses curated CSV files)
php artisan idn-area:setup --mode=local
๐ก Usage
๐๏ธ Provinces
use zaidysf\IdnArea\Facades\IdnArea; // Get all provinces $provinces = IdnArea::getProvinces(); // Returns: [['code' => '11', 'name' => 'ACEH'], ...] // Find specific province $province = IdnArea::findProvince('11'); // Returns: ['code' => '11', 'name' => 'ACEH'] // Search provinces by name $results = IdnArea::searchProvinces('jawa'); // Returns: [['code' => '32', 'name' => 'JAWA BARAT'], ...] // Check if province exists $exists = IdnArea::hasProvince('11'); // true
๐ข Regencies
// Get all regencies in a province $regencies = IdnArea::getRegencies('11'); // Aceh regencies // Returns: [['code' => '1101', 'province_code' => '11', 'name' => 'SIMEULUE'], ...] // Find specific regency $regency = IdnArea::findRegency('1101'); // Returns: ['code' => '1101', 'province_code' => '11', 'name' => 'SIMEULUE'] // Search regencies in specific province $results = IdnArea::searchRegencies('bandung', '32'); // Returns regencies containing 'bandung' in West Java // Search regencies across all provinces $allResults = IdnArea::searchRegencies('bandung'); // Check if regency exists $exists = IdnArea::hasRegency('1101'); // true
๐๏ธ Districts
// Get all districts in a regency $districts = IdnArea::getDistricts('1101'); // Simeulue districts // Returns: [['code' => '110101', 'regency_code' => '1101', 'name' => 'TEUPAH SELATAN'], ...] // Find specific district $district = IdnArea::findDistrict('110101'); // Returns: ['code' => '110101', 'regency_code' => '1101', 'name' => 'TEUPAH SELATAN'] // Search districts in specific regency $results = IdnArea::searchDistricts('selatan', '1101'); // Search districts across all regencies $allResults = IdnArea::searchDistricts('selatan'); // Check if district exists $exists = IdnArea::hasDistrict('110101'); // true
๐ก Villages
// Get all villages in a district $villages = IdnArea::getVillages('110101'); // Teupah Selatan villages // Returns: [['code' => '1101012001', 'district_code' => '110101', 'name' => 'LATIUNG'], ...] // Find specific village $village = IdnArea::findVillage('1101012001'); // Returns: ['code' => '1101012001', 'district_code' => '110101', 'name' => 'LATIUNG'] // Search villages in specific district $results = IdnArea::searchVillages('latiung', '110101'); // Search villages across all districts $allResults = IdnArea::searchVillages('latiung'); // Check if village exists $exists = IdnArea::hasVillage('1101012001'); // true
๐ Advanced Search & Utilities
// Get complete hierarchy (province with all children) $hierarchy = IdnArea::getHierarchy('11'); // Returns province with regencies, districts, and villages // Get multiple areas by codes $areas = IdnArea::getMultipleByCode(['11', '12', '13']); // Returns array of provinces with specified codes // Get statistics $stats = IdnArea::getStatistics(); // Returns: ['provinces' => 38, 'regencies' => 514, 'districts' => 7292, 'villages' => 84345] // Get all data (use with caution - large dataset) $allData = IdnArea::getAllData();
Using Models Directly
use zaidysf\IdnArea\Models\Province; use zaidysf\IdnArea\Models\Regency; // Eloquent relationships $province = Province::with('regencies')->find('11'); $regencyCount = $province->regencies->count(); // Search with scopes $searchResults = Province::search('jawa')->get();
๐ง Configuration
Publish the config file:
php artisan vendor:publish --tag="idn-area-config"
๐ API Mode (Recommended for Production)
// config/idn-area.php 'mode' => 'api', 'datatoko_api' => [ 'base_url' => env('IDN_AREA_DATATOKO_URL', 'https://data.toko.center'), 'access_key' => env('IDN_AREA_ACCESS_KEY'), 'secret_key' => env('IDN_AREA_SECRET_KEY'), ],
Add to your .env
:
IDN_AREA_MODE=api IDN_AREA_ACCESS_KEY=your_access_key IDN_AREA_SECRET_KEY=your_secret_key
Get API Keys: Contact DataToko for enterprise-grade API access with guaranteed uptime and real-time data updates.
๐ Local Mode (Development/Offline)
// config/idn-area.php 'mode' => 'local', // Uses curated CSV files
๐๏ธ Artisan Commands
# Initial setup php artisan idn-area:setup # Switch between modes php artisan idn-area:switch-mode api php artisan idn-area:switch-mode local # View package info php artisan idn-area # View statistics php artisan idn-area:stats # Cache management php artisan idn-area:cache warm php artisan idn-area:cache clear
๐งช Testing
composer test
๐ Changelog
Please see CHANGELOG for more information on what has changed recently.
๐ค Contributing
Please see CONTRIBUTING for details.
๐ Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
๐ Credits
๐ License
The MIT License (MIT). Please see License File for more information.
๐ฎ๐ฉ About Indonesian Data
This package provides official Indonesian administrative area data sourced from government databases. The data is curated and regularly updated to ensure accuracy and completeness.
Data Sources:
- Badan Pusat Statistik (BPS) - Indonesian Central Statistics Agency
- Official Government Administrative Records
- Validated and cleaned for consistency
Use Cases:
- E-commerce shipping forms
- Government applications
- Data analysis and reporting
- Location-based services
- Administrative systems