kodepandai / laravel-indonesia
Indonesia administrative data for laravel
Installs: 3 069
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 0
Forks: 201
Open Issues: 2
Requires
- php: ^7.3|^8.0
- ext-zip: *
- laravel/framework: ^7.0|^8.0|^9.0|^10.0|^11.0
- staudenmeir/eloquent-has-many-deep: ^1.11
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- orchestra/testbench: ^5.0|^6.0|^7.0|^8.0
- pestphp/pest: ^1|^2
- pestphp/pest-plugin-laravel: ^1|^2
This package is auto-updated.
Last update: 2024-11-02 09:19:59 UTC
README
Laravel package for Indonesia administrative data.
This is a lightweight version of laravolt/indonesia which ONLY provides model, migration, seeder and a simple API endpoint.
Comparison
Installation
Install with composer:
composer require kodepandai/laravel-indonesia
(Optional) publish the package migration and configuration:
php artisan vendor:publish --provider="KodePandai\Indonesia\IndonesiaServiceProvider"
Configuration
Open the config/indonesia.php
file and suits your need.
Usage
Seeder
This package automatically load indonesia migration, but to seed the database you must configure it manually.
Call IndonesiaDatabaseSeeder
in your DatabaseSeeder
:
// file: database/seeders/DatabaseSeeder.php use KodePandai\Indonesia\IndonesiaDatabaseSeeder; //.. public function run(): void { $this->call(IndonesiaDatabaseSeeder::class); } //..
Model
This package has 4 base models (Province
, City
, District
, Village
)
and each model has relations to other models.
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
API
This package provides API endpoint to get administrative data. The API is enabled by default, to disable it, change the configuration file.
Province
- Get all provinces
$ curl "http://localhost:8000/api/indonesia/provinces"
*Note: add parameter as_html=true
to get response as html options.
City
- Get all cities
$ curl "http://localhost:8000/api/indonesia/cities"
- Get cities by province_code or province_name
$ curl "http://localhost:8000/api/indonesia/cities?province_code=33" $ curl "http://localhost:8000/api/indonesia/cities?province_name=PAPUA"
*Note: add parameter as_html=true
to get response as html options.
District
- Get all districts
$ curl "http://localhost:8000/api/indonesia/districts"
- Get districts by city_code or city_name
$ curl "http://localhost:8000/api/indonesia/districts?city_code=3315" $ curl "http://localhost:8000/api/indonesia/districts?city_name=KOTA SEMARANG"
*Note: add parameter as_html=true
to get response as html options.
Village
- Get all villages
$ curl "http://localhost:8000/api/indonesia/villages"
- Get villages by district_code or district_name
$ curl "http://localhost:8000/api/indonesia/villages?district_code=337401" $ curl "http://localhost:8000/api/indonesia/villages?district_name=SEMARANG TENGAH"
*Note: add parameter as_html=true
to get response as html options.