2017 © Pedro Peláez
 

library laravel-countries

Get informations about countries.

image

lykegenes/laravel-countries

Get informations about countries.

  • Sunday, February 5, 2017
  • by Lykegenes
  • Repository
  • 1 Watchers
  • 5 Stars
  • 2,600 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 3 Open issues
  • 6 Versions
  • 7 % Grown

The README.md

Laravel Countries

Latest Version on Packagist Software License ![Build Status][ico-github-action] Total Downloads, (*1)

This package gives you access effortlessly to data from every country., (*2)

Install

Via Composer, (*3)

``` bash composer require lykegenes/laravel-countries, (*4)


## Usage You can search for a specific country using one of the following unique country codes : ``` 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

You can retrieve an array of countries using their region of one of their currencies : ``` php $countries = \Countries::getByCurrency('CAD'); /// A 3-letters currency code, (*5)

// Search by region $countries = \Countries::getByRegion(\Countries::$REGION_AFRICA); $countries = \Countries::getByRegion(\Countries::$REGION_AMERICAS); $countries = \Countries::getByRegion(\Countries::$REGION_ANTARCTICA); $countries = \Countries::getByRegion(\Countries::$REGION_ASIA); $countries = \Countries::getByRegion(\Countries::$REGION_EUROPE); $countries = \Countries::getByRegion(\Countries::$REGION_OCEANIA);, (*6)


Results will be returned as Country objects. These objects have the following helper methods : ``` php $country = \Countries::getByAlpha3Code('CAN'); $country->getAlpha2Code(); // 'CA' $country->getAlpha3Code(); // 'CAN' $country->getNumericCode(); // 124 $country->getOfficialName(); // 'Canada' $country->getAttributes(); // An array of all the raw attributes.

It is also possible to generate simple PHP array that can be used to generate an HTML select input. ``` php // All parameters are optionnal. These are the defaults. // $key The country attribute to use as key. (default: 'cca3', 3-letters country code from ISO3166) // $official True for the offical country name, False for the common name. (default: false) // $localization A 3-letter locale code to try to translate. Will default to English if it`s missing. (default: null) $countries = \Countries::getListForDropdown('cca3', false, 'fra');, (*7)

//This will return the following [ 'CAN' => 'Canada', 'USA' => 'États-Unis', ... ] ```, (*8)

Credits

License

The MIT License (MIT). Please see License File for more information., (*9)

The Versions