The Country::class provides a simple and effective way to manage and query countries in your application.
Here’s a quick introduction to what you can do with this model:
You'll find all the information you can retrieve by filtering a country.
We've presented it as an array for simplicity, but in reality, you'll be working with a Country::class collection.
use Lwwcas\LaravelCountries\Models\Country;
Country::inRandomOrder()->first()->toArray();
::: details Click me to view the output
{
"id": 30,
"lc_region_id": 2,
"uid": "01J95Z2ZRPSEJ1BKW90K4BJFZB",
"official_name": "Federative Republic of Brazil",
"slug": "brazil",
"name": "Brazil",
"capital": "Brasília",
"iso_alpha_2": "BR",
"iso_alpha_3": "BRA",
"iso_numeric": 76,
"international_phone": "55",
"geoname_id": "3469034",
"wmo": "BZ",
"independence_day": "1822-09-07",
"population": "212559417",
"area": "8515767",
"gdp": "1445",
"languages": [
"pt"
],
"tld": [
".br"
],
"alternative_tld": [],
"borders": [
"ar",
"bo",
"co",
"gf",
"gy",
"py",
"pe",
"sr",
"uy",
"ve"
],
"timezones": {
"main": {
"timezone_id": "America/Sao_Paulo",
"standard_time": "UTC−3"
},
"others": [
{
"timezone_id": "America/Manaus",
"standard_time": "UTC−4"
},
{
"timezone_id": "America/Rio_Branco",
"standard_time": "UTC−5"
}
]
},
"translations": [
{
"id": 30,
"lc_country_id": 30,
"name": "Brazil",
"slug": "brazil",
"locale": "en"
}
],
"currency": {
"code": "BRL",
"name": "Brazilian real",
"symbol": "R$",
"unit": {
"sub": "centavo",
"main": "real",
"to_unit": 100
},
"coins": {
"sub": [
"5",
"10",
"25",
"50"
],
"main": [
"1"
]
},
"banknotes": [
"2",
"5",
"10",
"20",
"50",
"100",
"200"
]
},
"flag_emoji": {
"css": "\\1F1E7\\1F1F7",
"hex": "🇧🇷",
"img": "🇧🇷",
"html": "🇧🇷",
"utf8": "🇧🇷",
"uCode": "U+1F1E7 U+1F1F7",
"utf16": "\\uD83C\\uDDE7\\uD83C\\uDDF7",
"decimal": "🇧🇷",
"shortcode": ":flag-br:"
},
"flag_colors": [
"Green",
"Yellow",
"Blue",
"White"
],
"flag_colors_web": [
"green",
"yellow",
"blue",
"white"
],
"flag_colors_contrast": [
"#FFFFFF",
"#000000",
"#FFFFFF",
"#000000"
],
"flag_colors_hex": [
"#009C3B",
"#FFDF00",
"#002776",
"#FFFFFF"
],
"flag_colors_rgb": [
"0,156,59",
"255,223,0",
"0,39,118",
"255,255,255"
],
"flag_colors_cmyk": [
"100,0,62,39",
"0,13,100,0",
"100,67,0,54",
"0,0,0,0"
],
"flag_colors_hsl": [
"147,100%,31%",
"51,100%,50%",
"217,100%,23%",
"0,0%,100%"
],
"flag_colors_hsv": [
"147,100%,61%",
"51,100%,100%",
"217,100%,46%",
"0,0%,100%"
],
"flag_colors_pantone": [
"Green C",
"Yellow 012 C",
"Reflex Blue C",
"White"
],
"region": {
"id": 2,
"iso_alpha_2": "AM",
"icao": "NAT",
"iucn": "Americas",
"tdwg": "NAM/SAM",
"is_visible": true,
"slug": "americas",
"name": "Americas",
"translations": [
{
"id": 2,
"lc_region_id": 2,
"name": "Americas",
"slug": "americas",
"locale": "en"
}
]
},
"extras": {
"id": 30,
"lc_country_id": 30,
"national_sport": "Football (Soccer)",
"cybersecurity_agency": "Department of Information Security and Cybersecurity (Departamento de Segurança da Informação e Comunicações)",
"popular_technologies": [
"PHP",
"JavaScript",
"Java",
"Python",
".NET",
"WordPress"
],
"internet": {
"speed": {
"average_fixed": "100 Mbps",
"average_mobile": "30 Mbps"
},
"penetration": "75%"
},
"religions": [
"Christianity (Roman Catholicism, Protestantism)",
"Spiritism",
"Afro-Brazilian religions"
],
"international_organizations": [
"United Nations",
"World Trade Organization (WTO)",
"BRICS",
"G20",
"Mercosur",
"Organization of American States (OAS)",
"Union of South American Nations (UNASUR)",
"Community of Latin American and Caribbean States (CELAC)"
]
},
"coordinates": {
"id": 30,
"lc_country_id": 30,
"latitude": "-15.7939",
"longitude": "-47.8828",
"degrees_with_decimal": "15.7939° S, 47.8828° W",
"degrees_minutes_seconds": "15°47'38.04\" S, 47°52'58.08\" W",
"degrees_and_decimal_minutes": "15°47.634' S, 47°52.968' W",
"gps": []
},
"is_visible": true,
}
:::
::: details Click me to view fillable data
/**
* The attributes that are mass assignable.
*
* [@var](https://github.com/var) array
*/
protected $fillable = [
'uid', // Unique identifier (ULID) for the country.
'lc_region_id', // Foreign key linking the country to a specific region.
'official_name', // The official name of the country (e.g., "United States of America").
'capital', // The capital city of the country.
'iso_alpha_2', // ISO 3166-1 alpha-2 country code (e.g., "US" for the United States).
'iso_alpha_3', // ISO 3166-1 alpha-3 country code (e.g., "USA" for the United States).
'iso_numeric', // ISO 3166-1 numeric country code (e.g., "840" for the United States).
'international_phone', // The country’s international dialing code (e.g., +1 for the United States).
'geoname_id', // The GeoNames geographical database ID for the country https://www.geonames.org/
'wmo', // Country abbreviations by the World Meteorological Organization (WMO).
'independence_day', // Year of the country's independence, if applicable.
'population', // The population of the country.
'area', // The area of the country in square kilometers (km²).
'gdp', // The Gross Domestic Product (GDP) of the country in billions of USD.
'languages', // Official languages spoken in the country.
'tld', // Top-level domain (e.g., ".us" for the United States).
'alternative_tld', // Alternative top-level domains (e.g., country-specific or alternative domain suffixes).
'borders', // List of bordering countries (if any).
'timezones', // The country's time zones, including main and additional ones.
'currency', // Information about the country's currency, including name, symbol, and units.
'flag_emoji', // The emoji representation of the country's flag.
'flag_colors', // Base colors of the flag.
'flag_colors_web', // Web-safe color names for the flag.
'flag_colors_contrast', // Contrast colors for improved readability on the flag.
'flag_colors_hex', // Hexadecimal color codes for the flag.
'flag_colors_rgb', // RGB (Red, Green, Blue) color values for the flag.
'flag_colors_cmyk', // CMYK (Cyan, Magenta, Yellow, Black) color values for the flag.
'flag_colors_hsl', // HSL (Hue, Saturation, Lightness) color values for the flag.
'flag_colors_hsv', // HSV (Hue, Saturation, Value) color values for the flag.
'flag_colors_pantone', // Pantone color codes for the flag.
'is_visible', // Boolean flag indicating whether the country is visible in the application.
];
:::
Why We Use UILD Instead of UUID for Country Listing
We chose to use UILD instead of UUID for listing countries in the database for a simple reason: new countries aren’t created every day. Since the number of countries is relatively stable, using UILD (which is shorter and more efficient) makes more sense for this specific case.
UUIDs are great for large-scale or frequently changing datasets, but for something as steady as a list of countries, UILD keeps things cleaner and faster without sacrificing uniqueness.
It’s all about keeping the database lean and efficient!
UILDs are shorter than UUIDs, which reduces the amount of storage needed and speeds up lookups, queries, and indexing. For a fixed dataset like countries, this optimization is a great fit.
With UILDs being less complex, your queries are easier to write and manage. This leads to simpler code and less chance for errors when retrieving or updating country records.
Since countries rarely change, UILD offers all the uniqueness we need without the overhead of UUID. It’s a perfect match for managing entities like countries, where the dataset is relatively small and stable.
Need a quick way to work with countries? Here are some handy snippets to get you started! Whether you're fetching countries by name, ISO codes, or filtering by regions, we've got you covered.
::: details Click me to view the code
.br).🇧🇷\1F1E7\1F1F7🇧🇷🇧🇷\uD83C\uDDE7\uD83C\uDDF7:flag-br:🇧🇷#009C3B0,156,59100,0,62,39147°,100%,31%147°,100%,61%#FFFFFF#FFDF00255,223,00,13,100,051°,100%,50%51°,100%,100%#000000#0027760,39,118100,67,0,54217°,100%,23%217°,100%,46%#FFFFFF#FFFFFF255,255,2550,0,0,00°,0%,100%0°,0%,100%#000000212,559,417
8,515,767 km²
UTC−3UTC−4UTC−5AR)BO)CO)GF)GY)PY)PE)SR)UY)VE)2, 5, 10, 20, 50, 100, 20015, 10, 25, 50100 Mbps30 Mbps75%
Departamento de Segurança da Informação e ComunicaçõesTrue
-15.7939-47.882815.7939° S, 47.8828° W15°47'38.04" S, 47°52'58.08" W15°47.634' S, 47°52.968' W:::
How can I help you explore Laravel packages today?