API Reference

Complete reference for all classes, methods, and functions.

Countries Class

The main class for accessing country data.

getOne(string $iso)

Get a single country by ISO code

getList(?string $sort)

Get all countries, optionally sorted

getByCurrency(string $code)

Filter countries by currency code

getByRegion(string $region)

Filter countries by region

search(string $query)

Search countries by name or capital

getListForSelect(string $display)

Get formatted options for select inputs

collect()

Get countries as Laravel Collection

Country Data Structure

Each country contains the following fields:

[
'name' => 'United States', // Official country name
'capital' => 'Washington D.C.', // Capital city
'iso_3166_2' => 'US', // ISO 3166-2 code (2 letters)
'iso_3166_3' => 'USA', // ISO 3166-3 code (3 letters)
'currency_code' => 'USD', // ISO 4217 currency code
'currency_name' => 'US Dollar', // Currency name
'currency_symbol' => '$', // Currency symbol
'calling_code' => '1', // International calling code
'region' => 'North America', // Geographic region
'languages' => ['en'], // Array of language codes
'flag' => 'πŸ‡ΊπŸ‡Έ', // Flag emoji
]

Helper Functions

Global helper functions for quick access:

country_name($code)

Get country name

country_flag($code)

Get country flag emoji

country_capital($code)

Get capital city

country_currency($code)

Get currency information

country_formatted($code)

Get formatted name with flag

country_exists($code)

Check if country code exists

countries_by_region($region)

Get countries in a region

countries_by_currency($currency)

Get countries using currency

Collection Macros

Extended Collection methods for country data:

byCountry($code)

Filter by country code

byRegion($region)

Filter by region

byCurrency($currency)

Filter by currency

searchCountries($query)

Search countries

countryNames()

Extract country names

countryCodes()

Extract country codes

countryFlags()

Extract flag emojis

withFlags()

Add display_name with flags

String Macros

Extended Str class methods:

Str::toCountryFlag($code)

Convert code to flag emoji

Str::fromCountryFlag($flag)

Convert flag to country code

Str::countryName($code)

Get country name

Validation Rules

Custom validation rules for forms:

ValidCountryCode

Validate country codes

ValidCurrencyCode

Validate currency codes

ValidRegion

Validate region names