• Stars
    star
    498
  • Rank 88,494 (Top 2 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Package Laravel yang berisi data Provinsi, Kabupaten/Kota, dan Kecamatan/Desa di seluruh Indonesia.

StyleCI Build Status Coverage Status

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 berokut.

$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

More Repositories

1

avatar

Plug n play avatar, turn name, email, and any other string into beautiful avatar (or gravatar), effortless.
PHP
1,791
star
2

laravolt

Main repository for Laravolt Platform. Open for ISSUES and PULL REQUESTS.
JavaScript
54
star
3

semantic-form

[READ ONLY] Semantic-UI form helper
PHP
51
star
4

metabase

Embed metabase dashboard and question in your application
PHP
24
star
5

auth

Laravel auth extended
PHP
13
star
6

camunda

Convenience Laravel HTTP client wrapper to interact with Camunda REST API.
PHP
12
star
7

mural

Ready to use comment widget for your Laravel application. Support Semantic UI theme by default.
PHP
10
star
8

packer

Laravel package generator
PHP
9
star
9

acl

Simple Access Control List (ACL) management for Laravel
PHP
8
star
10

eloquent-uuid

Universally Unique Identifier (UUID) for Laravel Eloquent
PHP
8
star
11

suitable

[READ ONLY] Semantic UI Table Builder
PHP
8
star
12

laravolt-project

Application skeleton powered by Laravolt
PHP
8
star
13

votee

Like dislike for any content. Built for Laravel.
PHP
8
star
14

thunderclap

[READ ONLY] CRUD Generator
PHP
6
star
15

password

Laravel password extended
PHP
4
star
16

ui

Admin template for laravolt based application
JavaScript
4
star
17

trail

Revision history for any Eloquent object
PHP
3
star
18

habit

The Laravolt Habit untuk panduan sehari-hari kodinganmu
2
star
19

base

Base application skeleton for Laravel
PHP
2
star
20

hologram

Laravel activity log viewer
PHP
2
star
21

support

[READ ONLY] Laravolt support
PHP
2
star
22

epicentrum

Epic Central User Management for Laravel
PHP
2
star
23

laravolt.github.io

Blade
2
star
24

comma

[READ ONLY] Content management for Laravolt Platform
PHP
2
star
25

crud

Instant CRUD: pagination, searching, filtering, sorting, auto validation rules, and more
PHP
2
star
26

etalase

Sample UI for Laravolt application
HTML
1
star
27

workflow

[READ ONLY] This package is used to connect Laravolt with Camunda BPMN to make it easier
PHP
1
star
28

awesome-project-resources

1
star
29

star

sip
PHP
1
star
30

menu

[READ ONLY] Menu builder with additional admin panel
PHP
1
star
31

platform

[READ ONLY] Laravolt core platform
CSS
1
star
32

onlyoffice

Blade component to embed ONLYOFFICE document
PHP
1
star
33

lingua

Laravel translation editor
1
star
34

email

Simple email management for Eloquent user object
PHP
1
star
35

indonesia-logo

PHP
1
star
36

senarai

Add your item to list
PHP
1
star
37

mailkeeper

[READ ONLY] Save mail to database for further use
PHP
1
star
38

epilog

[READ ONLY] Epic Laravel log viewer
PHP
1
star
39

playground

Play is the highest form or research.
PHP
1
star