Installation:
composer require stellarwhale/world
Publish the config (if needed) with:
php artisan vendor:publish --provider="StellarWhale\World\WorldServiceProvider"
First Use Case: Access countries via the World facade in a controller or service:
use StellarWhale\World\Facades\World;
$countries = World::countries(); // Returns a collection of all countries
API Routes:
The package registers API routes under /api/world. Test immediately:
php artisan route:list | grep world
Example: GET /api/world/countries returns JSON of all countries.
Data Retrieval:
World::countries(), World::states($countryId), etc., for type-hinted access in classes./api/world/{resource} for frontend or external services (e.g., React/Vue apps).$country = World::countryWithStatesAndCities($countryId);
Form Integration:
World::countries()->pluck('name', 'id') for Laravel Collective or Livewire dropdowns.use StellarWhale\World\Rules\ValidCountryId;
$request->validate(['country_id' => ['required', new ValidCountryId]]);
Localization:
'overrides' => [
'US' => ['name' => 'United States of America'],
],
Caching:
$countries = Cache::remember('world.countries', now()->addDays(7), function () {
return World::countries();
});
$this->mock(World::class)->shouldReceive('countries')->andReturn(collect([...]));
Data Mutability:
->toArray() or ->values() to modify data:
$countriesArray = World::countries()->toArray();
ID vs. Code:
1 for "United States")."America/New_York").dd(World::countries()->first()).API Route Conflicts:
/api/world. If you have a WorldController, rename it to avoid conflicts (e.g., CountryController).Performance:
World::cities()). Instead, scope by country/state:
$usCities = World::cities()->where('country_id', 1); // USA
database/world.json file exists (auto-generated on first install). Re-publish config if corrupted:
php artisan vendor:publish --force --provider="StellarWhale\World\WorldServiceProvider"
config/app.php under providers.Custom Data Sources:
$this->app->bind('world.repository', function () {
return new CustomWorldRepository();
});
StellarWhale\World\Contracts\WorldRepository.Add New Regions:
states or cities arrays in config/world.php:
'states' => [
'US' => [
'Alaska' => ['id' => 99, 'cities' => [...]],
],
],
Localization:
name key in config or use a language-specific file:
'lang' => [
'en' => ['US' => 'United States'],
'es' => ['US' => 'Estados Unidos'],
],
create or update forms.Excel::download(new CountriesExport, 'countries.csv');
$query = World::cities()
->where('country_id', $request->country_id)
->when($request->state_id, fn($q) => $q->where('state_id', $request->state_id));
How can I help you explore Laravel packages today?