PHP code example of kodepandai / laravel-indonesia

1. Go to this page and download the library: Download kodepandai/laravel-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/ */

    

kodepandai / laravel-indonesia example snippets


// file: database/seeders/DatabaseSeeder.php

use KodePandai\Indonesia\IndonesiaDatabaseSeeder;

//..
public function run(): void
{
    $this->call(IndonesiaDatabaseSeeder::class);
}
//..

use \KodePandai\Indonesia\Models\Province;
use \KodePandai\Indonesia\Models\City;
use \KodePandai\Indonesia\Models\District;
use \KodePandai\Indonesia\Models\Village;

$province = Province::first();
$province->cities; // get cities of the province
$province->districts; // get districts of the province
$province->villages; // get villages of the province

$city = City::first();
$city->province; // get province of the city
$city->districts; // get districts of the city
$city->villages; // get villages of the city

$district = District::first();
$district->province; // get province of the district
$district->city; // get city of the district
$district->villages; // get villages of the district

$village = Village::first();
$village->province; // get province of the village
$village->city; // get city of the village
$village->district; // get district of the village

php artisan vendor:publish --provider="KodePandai\Indonesia\IndonesiaServiceProvider"