1. Go to this page and download the library: Download enadabuzaid/country-data 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/ */
enadabuzaid / country-data example snippets
use Enadstack\CountryData\Facades\Geography;
// All active countries (ordered by name_en)
Geography::countries();
// Filter by tag: arab | gulf | middle-east | africa | asia …
Geography::countries('gulf');
// Single country by ISO-2 code (case-insensitive)
$jordan = Geography::country('JO');
$jordan->code; // 'JO'
$jordan->name_en; // 'Jordan'
$jordan->name_ar; // 'الأردن'
$jordan->flag; // '🇯🇴'
$jordan->dial; // '+962'
$jordan->timezones; // ['Asia/Amman']
$jordan->currency_code; // 'JOD'
// All capital cities
Geography::capitals();
// For select dropdowns
Geography::countriesForSelect(locale: 'en', filter: 'arab');
// [['value' => 'JO', 'label' => 'Jordan', 'flag' => '🇯🇴', 'dial' => '+962'], ...]
// All cities for a country
Geography::cities('JO');
// Single city by country + English name
Geography::city('JO', 'Amman');
// Capital city of a country
Geography::capital('JO');
// Search cities by partial name (EN or AR), optionally scoped to a country
Geography::searchCities('am');
Geography::searchCities('am', 'JO');
// For select dropdowns
Geography::citiesForSelect('JO', locale: 'ar');
// [['value' => 3, 'label' => 'عمان'], ...]
// All areas for a city (accepts City model or int ID)
Geography::areas($amman);
Geography::areas(3);
// Filter by type: governorate | district | neighborhood | zone
Geography::areas($amman, 'neighborhood');
// Grouped by type
Geography::areasByType($amman);
// Collection keyed by type: ['neighborhood' => [...], 'district' => [...]]
// Search areas within a city
Geography::searchAreas('down', $amman);
// For select dropdowns
Geography::areasForSelect($amman, locale: 'en', type: 'neighborhood');
// [['value' => 12, 'label' => 'Downtown', 'type' => 'neighborhood'], ...]
$jordan = Country::where('code', 'JO')->first();
// All areas across all of Jordan's cities
$jordan->areas;
// Filtered
$jordan->areas()->where('type', 'neighborhood')->get();
// All IANA timezone identifiers for a country
Geography::timezonesOf('JO'); // ['Asia/Amman']
Geography::timezonesOf('AE'); // ['Asia/Dubai']
// Timezone of a specific city (accepts City model or int ID)
Geography::timezoneForCity($amman); // 'Asia/Amman'
Geography::timezoneForCity(3); // 'Asia/Amman'
Geography::dialCodeOf('JO'); // '+962'
Geography::countryByDialCode('+962'); // Country model for Jordan
Geography::countryByDialCode('962'); // also works (without +)
// All distinct continent names
Geography::continents();
// Collection: ['Africa', 'Asia', ...]
// Countries on a continent (flat collection)
Geography::countriesByContinent('Asia');
// All countries grouped by continent
Geography::groupedByContinent();
// Collection keyed by continent name, each value a Collection of Countries
// Straight-line distance in km between two country centres
Geography::distanceBetween('JO', 'SA'); // ~1,400.0
// Cities within a radius — each result has a `distance` (float, km) attribute
$cities = Geography::citiesNear(lat: 31.9566, lng: 35.9457, radiusKm: 100, countryCode: 'JO');
$cities->first()->distance; // e.g. 0.42
// All cities of a country sorted by distance from a point
$cities = Geography::sortCitiesByDistance(31.9566, 35.9457, 'JO');
$cities->first()->name_en; // 'Amman'
// Areas near a coordinate within a city
$areas = Geography::areasNear(lat: 31.9566, lng: 35.9457, city: $amman, radiusKm: 10);
$areas->first()->distance; // km from the given point
use Enadstack\CountryData\Rules\ValidCountryCode;
use Enadstack\CountryData\Rules\ValidCityForCountry;
use Enadstack\CountryData\Rules\ValidAreaForCity;
$request->validate([
// Must be an active ISO-2 country code
'country_code' => ['untry_code)],
// Area must exist and belong to the given city
'area_id' => ['