Upgrading from v1
The Composer package remains kodefarmers/nepaldata, the PHP namespace remains KodeFarmers\NepalData, and the Laravel facade import is unchanged. Update your Composer constraint to ^2.0 and choose which callers should keep the original arrays and which should move to the typed API.
Preserve existing array responses
If a template, test fixture, stored payload, or downstream API client expects v1’s exact keys and values, start with raw(). In this table, NepalData:: refers to the Laravel facade. In standalone PHP, use $data->raw() on the core service.
| v1 call | v2 equivalent |
|---|---|
NepalData::all() or NepalData::getAllData() | NepalData::raw()->all() |
NepalData::all('nepali'), NepalData::all('devanagari'), or NepalData::getAllDataInDevanagari() | NepalData::raw()->all(Language::NEPALI) |
NepalData::provinces() | NepalData::raw()->provinces() |
NepalData::districts() | NepalData::raw()->districts() |
NepalData::with('districts')->provinces() | NepalData::raw()->provincesWithDistricts() |
NepalData::with('localbodies')->districts() | NepalData::raw()->districtsWithLocalBodies() |
Import KodeFarmers\NepalData\Language for the named language values. Omit the argument for English, or use Language::ENGLISH. Replace both old Nepali aliases with Language::NEPALI. The v2 API rejects unsupported codes instead of defaulting to English.
To reproduce with('localbodies')->only('administrations')->districts() in Nepali, flatten the group arrays within each district. The outer district keys are preserved:
use KodeFarmers\NepalData\Language;
$groupsByDistrict = $data->raw()->districtsWithLocalBodies(Language::NEPALI);
$namesByDistrict = array_map(
static fn (array $groups): array => array_merge(...array_values($groups)),
$groupsByDistrict
);
Omit the language argument for the English equivalent.
Adopt the typed API
provinces() and districts() now return query objects. Terminate a query with get() or all() for typed records, or toArray() for the new scalar row shape. localLevels() is now its own typed entry point. with() and only() are gone; query filters and relationships are explicit and produce independent selections.
use KodeFarmers\NepalData\Entities\Province;
$province = $data->provinces()->findOrFail(Province::KOSHI);
$districts = $province->districts()->get();
$ruralRows = $province->localLevels()->ruralMunicipalities()->toArray();
The typed API follows the nested source hierarchy, so names and ordering may differ from v1’s flat lists. Do not replace a legacy array call with a typed query’s toArray() if you need backward-compatible output: one preserves the old shape and the other exports v2 fields.
If Laravel code used app('NepalData'), change it to app(\KodeFarmers\NepalData\NepalData::class) or inject that class directly. The Laravel chapter shows both the facade and dependency injection. Use stable province and district constants for the typed API; local level IDs are only valid within the relevant language and data snapshot.