PHP code example of nurbekjummayev / laravel-region

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

    

nurbekjummayev / laravel-region example snippets


use Nurbekjummayev\LaravelRegion\Models\Region;
use Nurbekjummayev\LaravelRegion\Models\District;

// Find by COATO code
Region::findByCode('1735');
Region::findByTaxCode('35');

// Active regions with districts
Region::active()->with('districts')->get();

// Find district
District::findByCode('1735204');
District::query()->inRegion('1735')->get();

// Relationships
$district = District::findByCode('1735204');
$district->region->name;  // "Republic of Karakalpakstan"
$district->name;          // current locale

District::findByTaxCode(regionCode: '1735', districtTaxCode: '8');

$region = Region::findByCode('1735');

$region->name;                  // Current locale
$region->translatedName('ru');  // "Республика Каракалпакстан"
$region->translatedName('en');  // "Republic of Karakalpakstan"

// routes/web.php
Route::get('/regions/{region}', fn (Region $region) => $region);
Route::get('/districts/{district}', fn (District $district) => $district);

// /regions/1735 → Region model
// /districts/1735204 → District model
bash
php artisan migrate
php artisan region:seed