PHP code example of sitehandy / laravel-world

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

    

sitehandy / laravel-world example snippets


use Sitehandy\World\World;
$china = World::getByCode('cn');
$china->setLocale('zh-cn');
$china->name; // China
$china->local_name; // 中国
$china->full_name; // People's Republic of China
$china->local_full_name; // 中华人民共和国
$china->emoji; // 🇨🇳
$china->callingcode; // 86
$china->code; // CN
$china->code_alpha3; // CHN
$china->has_division; // true
$china->currency_code; // CNY
$china->currency_name; // Yuan Renminbi
$china->local_currency_name; // 人民币

'providers' => [
    // ...
    Sitehandy\World\WorldServiceProvider::class,
]

use Sitehandy\World\World;

$continents = World::Continents();

use Sitehandy\World\World;

$countries = World::Countries();

use Sitehandy\World\World;

$china = World::getByCode('cn');     // ISO-3166 alpha 2 code
$china = World::getByCode('chn');    // ISO-3166 alpha 3 code
$beijing = World::getByCode('cn-11'); // Beijing

use Sitehandy\World\Models\Continent;

$asia = Continent::getByCode('AS');
$countries = $asia->countries()->get();
// or use children method
$countries = $asia->children();

use Sitehandy\World\Models\Country;

$china = Country::getByCode('cn');
$asia = $china->parent(); // Returns the continent

use Sitehandy\World\Models\Country;

$china = Country::getByCode('cn');
$provinces = $china->divisions()->get();
// or use children method
$provinces = $china->children();

use Sitehandy\World\Models\Country;

$china = Country::getByCode('cn');
// Check has_division to determine if next level is division or city
if ($china->has_division) {
    $regions = $china->children(); // Returns divisions/provinces
} else {
    $cities = $china->children(); // Returns cities directly
}
bash
php artisan vendor:publish --force --provider="Sitehandy\World\WorldServiceProvider"
composer dump-autoload
php artisan world:init