laravolt / indonesia
Package Laravel yang berisi data Provinsi, Kabupaten/Kota, Kecamatan, dan Keluarahan/Desa di seluruh Indonesia.
Installs: 130 043
Dependents: 2
Suggesters: 0
Security: 0
Stars: 584
Watchers: 24
Forks: 201
Open Issues: 5
Requires
- php: ^7.3|^8.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
Requires (Dev)
- orchestra/testbench: ^6.0|^7.0|^8.0|^9.0
- php-coveralls/php-coveralls: ^2.1
- phpunit/phpunit: ^9.0|^10.5
Suggests
- laravolt/suitable: Required if you want to access editor panel
- spatie/geocoder: Synchronize latitude longitude data directly using Google's Geocoding Service
- dev-master / 1.0.x-dev
- v0.35
- v0.34
- v0.33
- v0.32
- v0.31
- v0.30
- v0.29
- v0.28
- v0.27
- v0.26
- v0.25
- v0.24
- v0.23
- v0.22
- v0.21
- v0.20
- v0.19
- v0.18
- v0.17
- v0.16
- v0.15
- v0.14
- v0.13
- v0.12
- v0.11
- v0.10
- v0.9
- v0.8
- v0.7
- v0.6
- v0.5
- v0.4
- v0.3
- v0.2
- v0.1
- dev-fix/kode-pos-palu
- dev-feat/data-2022-village-diff
- dev-feat/data-2022-district-diff
- dev-feature/updated-data-2022
This package is auto-updated.
Last update: 2024-11-09 14:57:15 UTC
README
LARAVOLT INDONESIA
Package Laravel yang berisi data Provinsi, Kabupaten/Kota, dan Kecamatan/Desa di seluruh Indonesia. Data wilayah diambil dari edwardsamuel/Wilayah-Administratif-Indonesia
Instalasi
Install Package Via Composer
composer require laravolt/indonesia
Daftarkan Service Provider dan Facade (Untuk Laravel < 5.5)
Mulai versi 5.5 ke atas, Laravel sudah support fitur auto discover sehingga tidak perlu lagi mendaftarkan Service Provider dan Facade secara manual.
Tambahkan Service Provider dan Facade pada config.app
'providers' => [ Laravolt\Indonesia\ServiceProvider::class ]
'aliases' => [ 'Indonesia' => Laravolt\Indonesia\Facade::class ]
Daftarkan Service Provider dan Facade untuk Lumen
Dalam file bootstrap/app.php
, uncomment baris berikut
$app->withFacades(); $app->withEloquent();
Dalam file bootstrap/app.php
, daftarkan service provider dan alias/facade dengan menambahkan kode berikut.
$app->register(Laravolt\Indonesia\ServiceProvider::class); // class aliases class_alias(Laravolt\Indonesia\Facade::class, 'Indonesia');
Untuk mengatur prefix tabel, buat file config/laravolt.php
, lalu copy kode berikut (ganti indonesia_
dengan nilai prefix tabel yang diinginkan),
<?php return [ 'indonesia' => [ 'table_prefix' => 'id_', ], ];
Lalu daftarkan konfigurasi dalam bootstrap/app.php
dengan menambahkan kode berikut.
$app->configure('laravolt');
Untuk selanjutnya, konfigurasi bisa dipanggil dengan cara config('laravolt.indonesia.table_prefix')
.
Publish Migration (Hanya Untuk Laravel/Lumen 5.2)
Jika Anda menggunakan Laravel/Lumen versi 5.3 ke atas, abaikan langkah di bawah ini. Untuk Laravel:
php artisan vendor:publish --provider="Laravolt\Indonesia\ServiceProvider"
Untuk Lumen, file migrations harus di-copy manual dari direktori vendor/laravolt/indonesia/database/migrations
atau Migrations
Jalankan Migration
php artisan migrate
Jalankan Seeder Untuk Mengisi Data Wilayah
php artisan laravolt:indonesia:seed
Untuk menambahkan seedernya ke file DatabaseSeeder.php
ikuti contoh berikut:
namespace Database\Seeders; use Illuminate\Database\Seeder; use Laravolt\Indonesia\Seeds\CitiesSeeder; use Laravolt\Indonesia\Seeds\VillagesSeeder; use Laravolt\Indonesia\Seeds\DistrictsSeeder; use Laravolt\Indonesia\Seeds\ProvincesSeeder; class DatabaseSeeder extends Seeder { /** * Seed the application's database. * * @return void */ public function run() { $this->call([ ProvincesSeeder::class, CitiesSeeder::class, DistrictsSeeder::class, VillagesSeeder::class, ]); } }
Penggunaan
\Indonesia::allProvinces() \Indonesia::paginateProvinces($numRows = 15) \Indonesia::allCities() \Indonesia::paginateCities($numRows = 15) \Indonesia::allDistricts() \Indonesia::paginateDistricts($numRows = 15) \Indonesia::allVillages() \Indonesia::paginateVillages($numRows = 15)
\Indonesia::findProvince($provinceId, $with = null) // array $with : ['cities', 'districts', 'villages', 'cities.districts', 'cities.districts.villages', 'districts.villages'] \Indonesia::findCity($cityId, $with = null) // array $with : ['province', 'districts', 'villages', 'districts.villages'] Indonesia::findDistrict($districtId, $with = null) // array $with : ['province', 'city', 'city.province', 'villages'] \Indonesia::findVillage($villageId, $with = null) // array $with : ['province', 'city', 'district', 'district.city', 'district.city.province']
Examples
Indonesia::findProvince(11, ['cities']); /* Will return Province Object { 'id' => 11, 'name' => 'ACEH', 'cities' => City Collections { City Object, City Object, City Object, ... } } */ Indonesia::findProvince(11, ['cities', 'districts.villages']); /* Will return Province Object { 'id' => 11, 'name' => 'ACEH', 'cities' => City Collections { City Object, City Object, City Object, ... }, 'districts' => District Collections { District Object { 'id' => 1101010 'city_id' => '1101' 'name' => 'TEUPAH SELATAN' 'province_id' => '11' 'villages' => Village Colletions { Village Object, Village Object, Village Object, ... } }, ... } } */
\Indonesia::search('jakarta')->all() \Indonesia::search('jakarta')->allProvinces() \Indonesia::search('jakarta')->paginateProvinces() \Indonesia::search('jakarta')->allCities() \Indonesia::search('jakarta')->paginateCities() \Indonesia::search('jakarta')->allDistricts() \Indonesia::search('jakarta')->paginateDistricts() \Indonesia::search('jakarta')->allVillages() \Indonesia::search('jakarta')->paginateVillages()
Testing
Run
vendor/bin/phpunit tests