PHP code example of dyangalih / laravel-regions

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

    

dyangalih / laravel-regions example snippets


use DyanGalih\LaravelRegion\Facades\Region;

// Search for a village globally
$villages = Region::searchVillages(query: 'Bakongan', limit: 10);

// Get a district with its full hierarchy
$district = Region::getDistrictById(1101010);

// Get regencies for a specific province
$regencies = Region::searchRegencies(provinceId: 11);

use DyanGalih\LaravelRegion\Services\RegionService;

public function __construct(
    protected RegionService $regionService
) {}

public function getMyData()
{
    return $this->regionService->getVillageById(1101010001);
}

use DyanGalih\LaravelRegion\Facades\Region;

Region::flushCache();
bash
# 1. Run migrations
php artisan migrate

# 2. Seed the data
php artisan indonesia:seed