Download the PHP package enadstack/laravel-country-data without Composer
On this page you can find all versions of the php package enadstack/laravel-country-data. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download enadstack/laravel-country-data
More information about enadstack/laravel-country-data
Files in enadstack/laravel-country-data
Package laravel-country-data
Short Description Laravel package for country information (config-based, reusable, and localized)
License MIT
Informations about the package laravel-country-data
Laravel Country Data
A full-featured Laravel geography package with countries, cities, and areas — backed by a database with caching, geospatial helpers, validation rules, a Livewire cascading dropdown, and an optional REST API.
Built with multilingual support (English & Arabic), region filters, and a clean Geography facade — ideal for any application that needs structured location data.
Features
- DB-backed geography — countries, cities, and areas as Eloquent models
- Selective seeding — choose which countries to seed interactively or via CLI flags
- Transparent caching — all reads cached, one-command flush
- Geography facade — clean API for countries, cities, areas, search, and select helpers
- Currency & timezone helpers — typed
CurrencyDatavalue object, dial-code lookup, continent grouping - Geospatial helpers — Haversine distance, cities/areas near a coordinate
- Validation rules —
ValidCountryCode,ValidCityForCountry,ValidAreaForCity - Livewire component — cascading Country → City → Area dropdowns, RTL-aware
- Optional REST API — 12 JSON endpoints, opt-in via
.env - Artisan commands — setup, cache-clear, stats
- Multilingual (EN + AR), region filters, and frontend select helpers
Requirements
- PHP
^8.2 - Laravel
^11.0or^12.0
Installation
Publish the config files:
Geography System Setup
1. Run the interactive setup command
The command will ask three things:
2. Non-interactive / CI options
What gets created
| Table | Content |
|---|---|
countries |
22 Arab League countries with currency, dial code, timezone, geo coordinates |
cities |
136 cities across all 22 countries (Jordan: all 12 governorates) |
areas |
276 areas. Amman is fully covered and two-level: 27 Greater Amman Municipality districts, each with its neighborhoods and major streets (207 Amman rows). Other cities remain flat. |
Seeders are idempotent — safe to re-run, they use updateOrInsert.
Geography Facade
Countries
Cities
Areas
Area hierarchy
Areas are a two-level tree. A root has parent_id = null (a district, a zone,
or any area in a city that has not been broken down yet); a child points at its
district. Amman is the first city modelled this way — every other city's areas are
roots, exactly as before.
On the model:
Area types: governorate, district, neighborhood, zone, and street.
street is used for major named streets (شارع المدينة المنورة, شارع مكة) — in
Jordanian addresses people locate themselves by street as readily as by
neighborhood, so these are selectable areas. A street is a line rather than a
polygon, so its parent_id is the district holding most of its length.
Amman's districts and localities are derived from OpenStreetMap (Amman Governorate, retrieved 2026-08-27). Neighborhoods are assigned to the district whose centre they are nearest, with well-known assignments pinned explicitly; a handful near district boundaries may warrant correction.
Country → Areas (HasManyThrough)
Currency & Timezone Helpers
Currency
Timezones
Dial Codes
Continents
Geospatial Helpers
All distance calculations use the Haversine formula (PHP-level, works with SQLite and all DB drivers).
Validation Rules
Phone Input (React)
A searchable dial-code picker (flag + +962) joined to a national-number
input. The selected country's ISO-2 code is kept in a hidden field; users only
see the flag and dial code. Pasting an international number (+962 772 432 330)
selects the country automatically.
1. Pass the countries from the server
2. Use the component — import it straight from the package (updates arrive
with composer update) or publish a copy to customise it:
Or publish a copy: php artisan country-data:publish-component --component=phone-input --type=react
(→ resources/js/components/custom/PhoneInput.tsx).
The component only depends on React and Tailwind utility classes using
shadcn/ui theme tokens (border-input, bg-popover, ring-ring, …).
| Prop | Type | Description |
|---|---|---|
countries |
PhoneCountryOption[] |
Output of Geography::phoneCountriesForSelect() |
countryCode / phone |
string \| null |
Controlled values (ISO-2 / national digits) |
onChange |
({ countryCode, dial, phone, e164 }) => void |
Fired on country or number change |
defaultCountry |
string |
Used while countryCode is empty |
countryCodeName / phoneName |
string |
Input names for native/<Form> posts (phone_country_code / phone) |
invalid, disabled, required, placeholder, searchPlaceholder, emptyText, id, className |
Presentation |
3. Validate and normalise on the server
ValidPhoneNumber checks digits only, at least 6 digits, and that dial code +
number fit E.164 (15 digits).
Livewire Cascading Dropdown
Requires Livewire 3. The component is auto-registered when Livewire is installed.
Basic usage
With options
Props
| Prop | Type | Default | Description |
|---|---|---|---|
locale |
string |
'en' |
Display language (en or ar) |
filter |
?string |
null |
Country filter tag (e.g. arab, gulf) |
showAreas |
bool |
false |
Show the third area dropdown |
required |
bool |
false |
Mark all selects as required |
countryField |
string |
'country_code' |
Hidden input name for country |
cityField |
string |
'city_id' |
Hidden input name for city |
areaField |
string |
'area_id' |
Hidden input name for area |
Events emitted
| Event | Payload |
|---|---|
country-selected |
['code' => 'JO'] |
city-selected |
['id' => 3] |
area-selected |
['id' => 12] |
Publish the view to customise
Published to: resources/views/vendor/country-data/livewire/geography-select.blade.php
REST API
The API is disabled by default. Enable it in .env:
Or in config/country-data.php:
Endpoints
Countries
| Method | URL | Description |
|---|---|---|
| GET | /api/geography/countries |
All countries (?filter=gulf&locale=ar) |
| GET | /api/geography/countries/{code} |
Single country by ISO-2 code |
| GET | /api/geography/countries/{code}/cities |
Cities for a country |
Cities & Areas
| Method | URL | Description |
|---|---|---|
| GET | /api/geography/cities/{id} |
Single city by ID |
| GET | /api/geography/cities/{id}/areas |
Areas for a city (?type=neighborhood) |
| GET | /api/geography/cities/{id}/areas/tree |
Districts for a city with their children nested |
| GET | /api/geography/areas/{id}/children |
Areas belonging to one district |
Currency & Continents
| Method | URL | Description |
|---|---|---|
| GET | /api/geography/currencies |
All unique currencies (?locale=ar) |
| GET | /api/geography/currencies/{code}/countries |
Countries using a currency |
| GET | /api/geography/continents |
All distinct continents |
| GET | /api/geography/continents/{name}/countries |
Countries on a continent |
Geospatial
| Method | URL | Description |
|---|---|---|
| GET | /api/geography/near/cities |
Cities near a coordinate (?lat=&lng=&radius=&country=) |
Search
| Method | URL | Description |
|---|---|---|
| GET | /api/geography/search/cities |
Search cities (?q=amman&country=JO) |
| GET | /api/geography/search/areas |
Search areas (?q=down&city_id=3) |
Response shape
Artisan Commands
| Command | Description |
|---|---|
php artisan country-data:setup |
Interactive migrate + selective seed |
php artisan country-data:setup --migrate |
Run migrations only |
php artisan country-data:setup --seed --all |
Seed all countries without prompting |
php artisan country-data:setup --seed --countries=JO,SA |
Seed specific countries |
php artisan country-data:setup --fresh --all |
Drop tables, migrate, seed all |
php artisan country-data:cache-clear |
Flush all geography cache entries |
php artisan country-data:stats |
Display seeded counts, cache status |
php artisan country-data:configure |
Choose config-based country dataset |
php artisan country-data:publish-component --component=phone-input --type=react |
Publish a Blade/Vue/React component (country-select, phone-input) |
country-data:stats output
Cache Configuration
Flush manually:
Or via artisan:
The cache is also flushed automatically after seeding.
Config Reference
Config-Based Facade (v1 — still available)
For lightweight use without a database, the original CountryData facade works from config:
File Structure
Testing
The test suite runs on an SQLite in-memory database — no external DB needed.
License
MIT — built by @enadabuzaid