PHP code example of opheus2 / laravel-countries

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

    

opheus2 / laravel-countries example snippets


use Orpheus\LaravelCountries\Country;

Country::macro(
    'getFlag',
    fn () => sprintf('https://www.countryflags.io/%s/flat/64.png', $this->getAlpha2Code())
);

$country = \Countries::getByAlpha3Code('CAN');
$flag = $country->getFlag();

// Output: https://www.countryflags.io/CA/flat/64.png


class CustomCountry
{
    public function getFlag(): string
    {
        return sprintf('https://www.countryflags.io/%s/flat/64.png', $this->getAlpha2Code());
    }
}

Country::mixin(new CustomCountry);

$country = \Countries::getByAlpha3Code('CAN');
$flag = $country->getFlag();
 php
$country = \Countries::getByAlpha2Code('CA'); // 2-letters country code from ISO3166
$country = \Countries::getByAlpha3Code('CAN'); // 3-letters country code from ISO3166
$country = \Countries::getByNumericCode(124); // 3-digits country code from ISO3166