Installation:
composer require nnjeim/world
php artisan vendor:publish --provider="Nnjeim\World\WorldServiceProvider" --tag="world-migrations"
php artisan migrate
Verify the world table exists in your database.
First Use Case: Fetch all countries via the World Facade in a controller or blade view:
use Nnjeim\World\Facades\World;
$countries = World::countries();
Or via API route: GET /api/countries.
Where to Look First:
config/world.php for configuration options (e.g., default locale).app/Providers/WorldServiceProvider.php for service binding details.Data Retrieval:
World facade for simplicity in controllers/blades:
$country = World::country(1); // By ID
$states = World::states(1); // States for country ID 1
$cities = World::cities(1, 2); // Cities for state ID 2 in country ID 1
use Nnjeim\World\Models\Country;
$country = Country::with('states.cities')->find(1);
API Integration:
/api/countries/{id}/states) for frontend consumption.Route::get('/api/countries/{id}/timezones', function ($id) {
return World::country($id)->timezones;
});
Localization:
config/world.php:
'localization' => [
'countries' => [
'US' => ['name' => 'United States of America (Custom)'],
],
],
php artisan vendor:publish --tag="world-lang"
Caching:
config/world.php:
'cache' => true,
php artisan cache:clear
Validation:
use Nnjeim\World\Rules\ValidCountry;
$request->validate(['country_id' => ['required', new ValidCountry]]);
Database Schema Mismatch:
world table, reset migrations:
php artisan migrate:fresh --seed
id column (used in relationships).Locale Conflicts:
app.php locale matches config/world.php locale to avoid missing translations.en if translations are missing:
config(['world.locale' => 'en']);
API Route Conflicts:
Route::prefix('v1')->group(function () {
Route::apiResource('countries', CountryController::class);
});
Performance:
$country = Country::with(['states.cities', 'timezones'])->find(1);
config(['world.cache' => env('APP_ENV') !== 'local']);
Data Integrity:
php artisan world:validate
php artisan world:fix
Missing Data:
php artisan db:seed --class=WorldSeeder
Facade Not Found:
config/app.php:
'providers' => [
Nnjeim\World\WorldServiceProvider::class,
],
Custom Data Sources:
WorldServiceProvider to bind custom repositories:
$this->app->bind(
\Nnjeim\World\Contracts\CountryRepository::class,
\App\Repositories\CustomCountryRepository::class
);
Add New Fields:
world table via migrations, then update models:
class Country extends Model {
protected $appends = ['custom_field'];
public function getCustomFieldAttribute() {
return $this->attributes['custom_field'] ?? null;
}
}
Webhooks/Events:
event(new \Nnjeim\World\Events\CountryUpdated($country));
Testing:
World facade in tests:
$this->assertCount(195, World::countries());
$this->mock(World::class)->shouldReceive('country')->andReturn($mockCountry);
How can I help you explore Laravel packages today?