emiliopedrollo/world
Laravel package providing a complete world dataset: countries, states, cities, timezones, currencies, and languages. Query via a World facade or built-in API routes with filters and field expansion, backed by migrations and a seeder for populating the database.
Installation
composer require nnjeim/world
php artisan vendor:publish --tag=world
php artisan migrate
php artisan db:seed --class=WorldSeeder # (~15 min)
world.php config file is published to config/ and adjust table names/fields if needed.First Use Case: Fetch Countries
use Nnjeim\World\World;
$countries = World::countries()->data;
$action->success to handle failures gracefully.API Endpoint Alternative
GET /api/countries
success, message, and data keys.Facade-Based Access
World::countries()World::states($countryId)World::cities($stateId)World::timezones()World::currencies()World::languages()Example with filtering:
$states = World::states(182, ['fields' => 'cities'])->data;
API Integration
GET /api/{endpoint} with query params:
GET /api/states?filters[country_id]=182&fields=cities
fields (e.g., cities) and filters (e.g., country_id).Eager Loading for Performance
$countryWithStates = World::countries()->with('states')->data;
app/Models/ after seeding).Customizing Responses
$countries = collect(World::countries()->data)->map(fn($c) => new CountryDto($c));
Validation
$country = World::countries()->data->firstWhere('id', $request->country_id);
if (!$country) abort(404);
Caching
$countries = Cache::remember('world.countries', 86400, fn() => World::countries()->data);
Localization
name_{locale} fields (if published) for multilingual support:
$country = World::countries()->where('id', 182)->first();
$name = $country->name_en; // or name_es, etc.
Testing
World::shouldReceive('countries')->andReturn((object) ['success' => true, 'data' => []]);
Seeder Duration
WorldSeeder takes ~15 minutes to run. Avoid running it in CI/CD unless necessary.Table Name Conflicts
countries, states, etc.) may conflict with existing apps.config/world.php before seeding.Missing Relationships
states on Country). Define them manually:
// app/Models/Country.php
public function states() { return $this->hasMany(State::class); }
API Rate Limiting
laravel-world.com) may throttle requests. Prefer local DB access for production.Optional Fields
iso_code, phone_code, or capital are optional. Ensure they’re enabled in config/world.php if needed.Check Seeder Status
php artisan db:show
Facade vs. API Inconsistencies
Query Debugging
DB_LOG_QUERIES=true
storage/logs/laravel.log for slow queries.Custom Fields
Schema::table('countries', function (Blueprint $table) {
$table->string('custom_field')->nullable();
});
Additional Endpoints
routes/web.php:
Route::get('/api/custom', function () {
return World::countries()->with('states')->data;
});
Local Overrides
php artisan vendor:publish --tag=world-views
app/Models/ or resources/views/ as needed.Performance Optimization
country_id in states table):
Schema::table('states', function (Blueprint $table) {
$table->index('country_id');
});
How can I help you explore Laravel packages today?