1. Go to this page and download the library: Download turahe/master-data 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/ */
use Turahe\Master\Models\Country;
use Turahe\Master\Models\Province;
use Turahe\Master\Models\City;
use Turahe\Master\Models\Bank;
use Turahe\Master\Models\Currency;
// Get all countries
$countries = Country::all();
// Get Indonesia
$indonesia = Country::where('name', 'Indonesia')->first();
// Get provinces in Indonesia
$provinces = $indonesia->provinces;
// Get cities in a specific province
$jakarta = Province::where('name', 'DKI Jakarta')->first();
$cities = $jakarta->cities;
// Get banks
$banks = Bank::all();
// Get currencies
$currencies = Currency::all();
use Turahe\Master\Master;
// Access models through facade
$countries = Master::country()->all();
$provinces = Master::province()->all();
$cities = Master::city()->all();
$banks = Master::bank()->all();
// Country -> Provinces
$country = Country::find(1);
$provinces = $country->provinces;
// Province -> Cities
$province = Province::find(1);
$cities = $province->cities;
// City -> Districts
$city = City::find(1);
$districts = $city->districts;
// District -> Villages
$district = District::find(1);
$villages = $district->villages;
// Search cities by name
$cities = City::where('name', 'like', '%Jakarta%')->get();
// Get cities by province
$cities = City::where('province_id', $provinceId)->get();
// Get banks by code
$bank = Bank::where('code', '008')->first(); // Bank Mandiri
Country::all() // Get all countries
Country::find($id) // Find by ID
Country::where('name', $name) // Find by name
$country->provinces // Get related provinces
Province::all() // Get all provinces
Province::find($id) // Find by ID
Province::where('country_id', $id) // Get by country
$province->cities // Get related cities
$province->country // Get parent country
City::all() // Get all cities
City::find($id) // Find by ID
City::where('province_id', $id) // Get by province
$city->districts // Get related districts
$city->province // Get parent province
Bank::all() // Get all banks
Bank::where('code', $code) // Find by bank code
Bank::where('name', $name) // Find by bank name
Currency::all() // Get all currencies
Currency::where('code', $code) // Find by currency code
Currency::where('name', $name) // Find by currency name