From 5d118a22eb626c9a9eb556310d14e4b19c13a935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Escribano?= Date: Tue, 3 Mar 2026 13:00:30 +0100 Subject: [PATCH] Make country native field required with name fallback If native is not provided in JSON data, it falls back to the country name. Changelog: changed --- .../migrations/0000_03_07_190506_create_countries_table.php | 2 +- src/Models/Country.php | 4 ++-- tests/Feature/Models/ModelConfigTest.php | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/database/migrations/0000_03_07_190506_create_countries_table.php b/database/migrations/0000_03_07_190506_create_countries_table.php index d299696..e519110 100755 --- a/database/migrations/0000_03_07_190506_create_countries_table.php +++ b/database/migrations/0000_03_07_190506_create_countries_table.php @@ -39,7 +39,7 @@ public function up(): void } $table->string('tld', 8); - $table->string('native', 80)->nullable(); + $table->string('native', 80); $table->string('region', 80); if (config()->boolean('atlas.entities.regions')) { diff --git a/src/Models/Country.php b/src/Models/Country.php index 9c9e039..f4f8961 100644 --- a/src/Models/Country.php +++ b/src/Models/Country.php @@ -18,7 +18,7 @@ * @property string|null $capital * @property string|null $currency_code * @property string $tld - * @property string|null $native + * @property string $native * @property string $region_name * @property int|null $region_id * @property string|null $subregion_name @@ -147,7 +147,7 @@ public static function fromJsonToDBRecord(array $jsonItem): array 'phonecode' => $jsonItem['phonecode'], 'capital' => $jsonItem['capital'], 'tld' => $jsonItem['tld'], - 'native' => $jsonItem['native'], + 'native' => $jsonItem['native'] ?? $jsonItem['name'], 'region_name' => $jsonItem['region'], 'subregion_name' => $jsonItem['subregion'], 'nationality' => $jsonItem['nationality'], diff --git a/tests/Feature/Models/ModelConfigTest.php b/tests/Feature/Models/ModelConfigTest.php index 8f4181a..4ec571a 100644 --- a/tests/Feature/Models/ModelConfigTest.php +++ b/tests/Feature/Models/ModelConfigTest.php @@ -21,6 +21,7 @@ 'numeric_code' => '999', 'phonecode' => '99', 'tld' => '.ts', + 'native' => 'Test', 'region_name' => 'Test Region', 'nationality' => 'Tester', 'translations' => json_encode(['en' => 'Test']),