PHP code example of khudayberdiyev / uzbekistan-regions
1. Go to this page and download the library: Download khudayberdiyev/uzbekistan-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/ */
khudayberdiyev / uzbekistan-regions example snippets
use Khudayberdiyev\UzbekistanRegions\Models\Region;
use Khudayberdiyev\UzbekistanRegions\Models\District;
use Khudayberdiyev\UzbekistanRegions\Models\Quarter;
$region = Region::with('districts.quarters')->find(2);
$region->getName(); // name in the active locale
$region->type; // region | city | republic
$region->name_ru; // or an explicit language
$region->districts; // districts of the region
$region->quarters; // every quarter in the region (hasManyThrough)
$district = District::find(10);
$district->region;
$district->quarters;
$district->isCity(); // Andijon shahri vs Andijon tumani
District::ofType(District::TYPE_CITY)->get(); // the 34 cities (shahar)
District::ofType(District::TYPE_DISTRICT)->get(); // the 175 districts (tuman)
Region::ofType(Region::TYPE_REGION)->get(); // the 12 regions (viloyat)
// case insensitive search anywhere in the name, in the active locale
District::search('and')->get();
// "name" is resolved to the column of the active locale
Quarter::sortBy('name', 'desc')->get();
public function district(): BelongsTo
{
return $this->belongsTo(\Khudayberdiyev\UzbekistanRegions\Models\District::class);
}
'routes' => [
'enabled' => true, // set to false if you only need the models
'prefix' => 'api/v1',
'middleware' => ['api', SetLocale::class],
],
'locales' => ['uz', 'oz', 'ru'],
'default_locale' => 'uz',
'connection' => null, // a dedicated database connection, if you use one
'data_path' => null, // your own JSON files, if you maintain them