Download the PHP package imujas9/laravel-world without Composer
On this page you can find all versions of the php package imujas9/laravel-world. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-world
๐ Laravel World
World countries, states, and cities for Laravel โ with multi-language support. Works without a database out of the box. Switch to a database driver any time with a single env variable.
โจ What Makes This Different
| Feature | Laravel World | Others |
|---|---|---|
| Works without a database | โ | โ |
| Switch to DB with one env var | โ | โ |
| Auto locale detection | โ | โ |
| Multi-language in one query | โ | โ |
| City translations on demand | โ | โ |
| 20+ languages for countries & states | โ | Partial |
| Fluent chainable API | โ | Limited |
| Partial name search & operators | โ | โ |
๐ฆ What's Included
- 250 countries โ numeric ID, ISO codes, dialling codes, currencies, flags, regions, capital cities, TLD, coordinates
- 5,308 states / provinces โ linked to countries by ID and code, with administrative type
- 156,025 cities โ linked to states and countries by ID and code, with coordinates
- 20 languages for country names ยท 27 for states ยท 24 for cities (downloaded on demand)
Requirements & Installation
- PHP 8.1+ ยท Laravel 10, 11, 12, or 13
No migrations, no seeding, no config. Auto-registers and works immediately.
Quick Start
โ๏ธ Configuration
๐ Locale Support
The package reads `app()->getLocale()` automatically. No `lang()` call needed once locale is set in middleware. **Resolution order** (when `lang()` is not called): 1. `app()->getLocale()` โ set by middleware or `App::setLocale()` 2. `config('world.default_lang')` โ `WORLD_LANG` env value 3. `'en'` โ hardcoded fallback Locale strings are normalised: `en_US` โ `en`, `zh_CN` โ `zh`. **Middleware example:** **Fallback behaviour:** | Locale | Translation file exists | Result | | ------- | ----------------------- | ---------------------------- | | `hi` | โ | Hindi name | | `ga` | โ | Falls back to `default_lang` | | `en_US` | โ normalised to `en` | English name | `lang()` always overrides the locale for that specific query.๐๏ธ City Translations
City names work in English out of the box. Translations are **not bundled** (they add 51 MB to every install) โ download only what you need: Once downloaded, translations are used automatically: **Available:** `ar` `bn` `br` `de` `es` `fa` `fr` `ga` `hi` `hr` `hy` `id` `it` `ja` `ko` `nl` `pl` `pt` `ru` `tr` `uk` `ur` `vi` `zh` > Add `php artisan world:translations hi` to your deploy script for the languages your app uses.๐๏ธ Database Driver
Use the database driver when you need SQL joins, full-text search, or indexing on millions of rows. > Re-seed: `php artisan world:seed --truncate` Your application code stays **exactly the same** โ the driver swap is transparent. **When to use each driver:** | Scenario | Recommended driver | | -------------------------------------------------- | ------------------ | | Read-only lookups, dropdowns, country picker | `file` (default) | | SQL `JOIN` to your own tables | `database` | | Full-text search with relevance ranking | `database` | | Multi-tenant SaaS โ no shared DB schema constraint | `file` | | High-traffic API โ want to avoid repeated JSON I/O | `file` + cache | | You already manage a world-data migration workflow | `database` | **DB performance notes:** - `paginate()` runs a `COUNT(*)` + a single `LIMIT/OFFSET` query โ no full table scan. - An index on `name` is created for all three tables. Use `whereLike('name', 'Ind%')` for fast prefix searches. - For suffix / infix LIKE (`%istan%`), consider a full-text index on your database engine.๐ API Reference
### Country ### State ### City๐ Result Objects
All methods return consistent value objects regardless of driver. ### CountryData | Property | Type | Description | | ------------ | -------------- | ------------------------------------------------- | | `id` | `int` | Numeric ID | | `code` | `string` | ISO2 (e.g. `IN`) | | `iso3` | `string` | ISO3 (e.g. `IND`) | | `phone_code` | `string` | Dialling code (e.g. `91`) | | `currency` | `string` | ISO 4217 (e.g. `INR`) | | `flag` | `string\|null` | Emoji flag (e.g. `๐ฎ๐ณ`) | | `region` | `string\|null` | e.g. `Asia` | | `subregion` | `string\|null` | e.g. `Southern Asia` | | `capital` | `string\|null` | Capital city (e.g. `New Delhi`) | | `tld` | `string\|null` | Top-level domain (e.g. `.in`) | | `latitude` | `string\|null` | Country centre latitude | | `longitude` | `string\|null` | Country centre longitude | | `name` | `string\|null` | Translated name (single lang) | | `names` | `array` | `['en' => 'India', 'hi' => 'เคญเคพเคฐเคค']` (multi-lang) | ### StateData | Property | Type | Description | | -------------- | -------------- | ----------------------------- | | `id` | `int` | Numeric ID | | `code` | `string` | State code | | `country_code` | `string` | Parent country ISO2 | | `country_id` | `int` | Parent country numeric ID | | `type` | `string\|null` | State / Province / Regionโฆ | | `latitude` | `string\|null` | | | `longitude` | `string\|null` | | | `name` | `string\|null` | Translated name (single lang) | | `names` | `array` | Translated names (multi-lang) | ### CityData | Property | Type | Description | | -------------- | ----------- | ----------------------------------------------- | | `id` | `int` | Numeric ID | | `state_code` | `string` | Parent state code | | `country_code` | `string` | Parent country ISO2 | | `state_id` | `int\|null` | Parent state numeric ID (DB driver only) | | `country_id` | `int\|null` | Parent country numeric ID (DB driver only) | | `latitude` | `string\|null` | | | `longitude` | `string\|null` | | | `name` | `string\|null` | Translated name (single lang) | | `names` | `array` | Translated names (multi-lang) |๐ Filtering & Search
All three facades share the same fluent filtering API. ### Equality (default) ### Comparison operators ### LIKE / partial match ### whereIn ### Chaining multiple filters > **File driver note:** LIKE filtering on `name` for countries and states matches the > translated name in the active language. For cities the stored English name is used. > All other fields (`code`, `capital`, `region`, `currency`, etc.) are matched against > the raw data.๐ Pagination
`paginate()` behaves like Laravel's native paginator โ it reads the current page from the `?page` query parameter automatically. The returned `LengthAwarePaginator` carries the correct `path` and query string, so `$countries->links()` renders proper next/prev URLs in Blade templates. **Database driver:** paginate executes a `COUNT(*)` query + a single `LIMIT/OFFSET` data query โ no full table scan. **File driver:** paginate streams/filters all matching records to count, then returns only the requested page slice.๐ Available Languages
> Missing translations fall back to the English name automatically. > City translations must be downloaded separately โ see [City Translations](#๏ธ-city-translations). | Code | Language | Countries | States | Cities | | ---- | -------------------- | --------- | ------ | ------ | | `en` | English | โ | โ | โ | | `ar` | Arabic | โ | โ | โ | | `bn` | Bengali | โ | โ | โ | | `br` | Breton | โ | โ | โ | | `de` | German | โ | โ | โ | | `el` | Greek | โ | โ | โ | | `es` | Spanish | โ | โ | โ | | `et` | Estonian | โ | โ | โ | | `fa` | Persian | โ | โ | โ | | `fi` | Finnish | โ | โ | โ | | `fr` | French | โ | โ | โ | | `ga` | Irish | โ | โ | โ | | `gu` | Gujarati | โ | โ | โ | | `hi` | Hindi | โ | โ | โ | | `hr` | Croatian | โ | โ | โ | | `hy` | Armenian | โ | โ | โ | | `id` | Indonesian | โ | โ | โ | | `it` | Italian | โ | โ | โ | | `ja` | Japanese | โ | โ | โ | | `ko` | Korean | โ | โ | โ | | `nl` | Dutch | โ | โ | โ | | `pl` | Polish | โ | โ | โ | | `pt` | Portuguese | โ | โ | โ | | `ru` | Russian | โ | โ | โ | | `tr` | Turkish | โ | โ | โ | | `uk` | Ukrainian | โ | โ | โ | | `ur` | Urdu | โ | โ | โ | | `vi` | Vietnamese | โ | โ | โ | | `zh` | Chinese (Simplified) | โ | โ | โ |๐ Model Traits
Drop a trait into any Eloquent model to get `country`, `state`, and `city` accessors that work with both drivers. ### HasWorldRelations โ all in one ### Individual traits | Trait | Column needed | Type | | ------------ | ------------- | -------------------- | | `HasCountry` | `country_id` | `unsignedBigInteger` | | `HasState` | `state_id` | `unsignedBigInteger` | | `HasCity` | `city_id` | `unsignedBigInteger` | ### Using string codes instead of integer IDs ### Driver behaviour | | File driver | Database driver | | ----------------------- | ---------------- | ------------------------------ | | `$user->country` | โ `CountryData` | โ `CountryData` | | `User::with('country')` | โ no DB table | โ eager loads โ `CountryData` |๐ ๏ธ Contributing
Contributions, bug reports, and feature requests are welcome. 1. Fork the repo ยท create a branch ยท write tests ยท open a PR **Updating world data** โ all data lives in `resources/data/` as plain JSON: | File | Purpose | | ------------------------------------ | ------------------------------------------ | | `countries.json` | Country base data | | `states.json` | State base data | | `cities.json` | City base data | | `translations/countries/{lang}.json` | Country names per language | | `translations/states/{lang}.json` | State names per language | | `translations/cities/{lang}.json` | City names per language (keyed by city ID) | To add a new language, create `translations/countries/{lang}.json` with `{ "ISO2": "Name" }` pairs and repeat for states/cities.About
Hi, I'm Ujas Patel โ a Backend Developer (TALL Stack), based in Ahmedabad, India. I built this package because every existing world-data solution for Laravel forces a database setup before you can use even a simple country list. Laravel World works out of the box โ and scales to a full database driver when you need it.
Reach out: imujaspatel [at] gmail [dot] com
Support
| Need | Where to go |
|---|---|
| ๐ Bug | Open an issue |
| ๐ก Feature request | Open an issue |
| โ Question | Start a discussion |
If this package saved you time, a โญ on GitHub goes a long way.
License
This package is open-source software licensed under the MIT License. Feel free to use, modify, and distribute it according to the terms of the license.
All versions of laravel-world with dependencies
illuminate/support Version ^10.0|^11.0|^12.0|^13.0
illuminate/database Version ^10.0|^11.0|^12.0|^13.0
illuminate/console Version ^10.0|^11.0|^12.0|^13.0