PHP code example of illusi03 / indonesia

1. Go to this page and download the library: Download illusi03/indonesia library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

illusi03 / indonesia example snippets


'providers' => [

    Laravolt\Indonesia\ServiceProvider::class

]

'aliases' => [

    'Indonesia' => Laravolt\Indonesia\Facade::class

]

$app->withFacades();
$app->withEloquent();

$app->register(Laravolt\Indonesia\ServiceProvider::class);


// class aliases
class_alias(Laravolt\Indonesia\Facade::class, 'Indonesia');



return [
    'indonesia' => [
        'table_prefix' => 'id_',
    ],
];

$app->configure('laravolt');

php artisan vendor:publish --provider="Laravolt\Indonesia\ServiceProvider"

php artisan migrate

php artisan laravolt:indonesia:seed

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,
        ]);
    }
}


\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']

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()