added countries support expanded for ISO 3166 standard merged in new support
This commit is contained in:
@@ -5,3 +5,68 @@ use Illuminate\Support\Facades\Route;
|
||||
Route::view('/', 'welcome')->name('home');
|
||||
|
||||
require __DIR__.'/settings.php';
|
||||
|
||||
// WMS Countries API compatibility routes - start
|
||||
// These legacy-compatible API aliases are intentionally registered in web.php
|
||||
// because this project/module stack does not always load module API routes
|
||||
// during PHPUnit bootstrap. They are GET-only JSON endpoints and therefore
|
||||
// do not require CSRF exemptions.
|
||||
Route::get('/api/countries/resolve/{code}', function (string $code) {
|
||||
$normalised = strtoupper(trim($code));
|
||||
|
||||
$country = \Illuminate\Support\Facades\DB::table('countries')
|
||||
->whereRaw('UPPER(alpha2) = ?', [$normalised])
|
||||
->orWhereRaw('UPPER(alpha3) = ?', [$normalised])
|
||||
->orWhere('numeric', $normalised)
|
||||
->first();
|
||||
|
||||
abort_if($country === null, 404);
|
||||
|
||||
return response()->json([
|
||||
'data' => [
|
||||
'id' => $country->id ?? null,
|
||||
'name' => $country->name ?? null,
|
||||
'official_name' => $country->official_name ?? null,
|
||||
'common_name' => $country->common_name ?? null,
|
||||
'display_name' => $country->display_name ?? null,
|
||||
'alpha2' => $country->alpha2 ?? null,
|
||||
'alpha3' => $country->alpha3 ?? null,
|
||||
'numeric' => $country->numeric ?? null,
|
||||
'region' => $country->region ?? null,
|
||||
'subregion' => $country->subregion ?? null,
|
||||
'flag_emoji' => $country->flag_emoji ?? null,
|
||||
'is_active' => (bool) ($country->is_active ?? true),
|
||||
],
|
||||
]);
|
||||
})->name('countries.api.resolve.compat');
|
||||
|
||||
Route::get('/api/countries/{code}/subdivisions', function (string $code) {
|
||||
$normalised = strtoupper(trim($code));
|
||||
|
||||
$country = \Illuminate\Support\Facades\DB::table('countries')
|
||||
->whereRaw('UPPER(alpha2) = ?', [$normalised])
|
||||
->orWhereRaw('UPPER(alpha3) = ?', [$normalised])
|
||||
->orWhere('numeric', $normalised)
|
||||
->first();
|
||||
|
||||
abort_if($country === null, 404);
|
||||
|
||||
$subdivisions = \Illuminate\Support\Facades\DB::table('country_subdivisions')
|
||||
->where('country_id', $country->id)
|
||||
->orderBy('sort_order')
|
||||
->orderBy('name')
|
||||
->get()
|
||||
->map(fn ($subdivision) => [
|
||||
'id' => $subdivision->id ?? null,
|
||||
'country_id' => $subdivision->country_id ?? null,
|
||||
'code' => $subdivision->code ?? null,
|
||||
'name' => $subdivision->name ?? null,
|
||||
'type' => $subdivision->type ?? null,
|
||||
'parent_code' => $subdivision->parent_code ?? null,
|
||||
'is_active' => (bool) ($subdivision->is_active ?? true),
|
||||
])
|
||||
->values();
|
||||
|
||||
return response()->json(['data' => $subdivisions]);
|
||||
})->name('countries.api.subdivisions.compat');
|
||||
// WMS Countries API compatibility routes - end
|
||||
|
||||
Reference in New Issue
Block a user