Download the PHP package enadabuzaid/country-data without Composer
On this page you can find all versions of the php package enadabuzaid/country-data. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download enadabuzaid/country-data
More information about enadabuzaid/country-data
Files in enadabuzaid/country-data
Package country-data
Short Description Laravel package for country information (config-based, reusable, and localized)
License MIT
Informations about the package 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 |
101 areas (Jordan fully covered — 32 Amman neighborhoods + all governorates) |
Seeders are idempotent — safe to re-run, they use updateOrInsert.
Geography Facade
Countries
Cities
Areas
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
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) |
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 |
Publish Blade/Vue/React frontend component |
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