added countries support expanded for ISO 3166 standard merged in new support

This commit is contained in:
Mark Gregory
2026-06-15 10:31:58 +01:00
parent 6acc6de707
commit 57d2507db9
19 changed files with 1118 additions and 120 deletions
@@ -0,0 +1,144 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Add enterprise ISO 3166 support fields used by platform administration,
* address validation, logistics, billing, carrier and compliance workflows.
*/
public function up(): void
{
Schema::table('countries', function (Blueprint $table): void {
$columns = Schema::getColumnListing('countries');
if (! in_array('native_name', $columns, true)) {
$table->string('native_name')->nullable()->after('display_name')->comment('Native/local country name where available.');
}
if (! in_array('capital', $columns, true)) {
$table->string('capital')->nullable()->after('native_name')->comment('Administrative capital city where applicable.');
}
if (! in_array('continent', $columns, true)) {
$table->string('continent', 64)->nullable()->index()->after('capital')->comment('Continent used for reporting and regional grouping.');
}
if (! in_array('intermediate_region', $columns, true)) {
$table->string('intermediate_region')->nullable()->index()->after('subregion')->comment('UN M49 intermediate region where applicable.');
}
if (! in_array('sovereignty_status', $columns, true)) {
$table->string('sovereignty_status', 64)->nullable()->index()->after('independent')->comment('Sovereignty or territory status.');
}
if (! in_array('un_member', $columns, true)) {
$table->boolean('un_member')->nullable()->index()->after('sovereignty_status')->comment('Whether the country is a United Nations member state.');
}
if (! in_array('calling_code', $columns, true)) {
$table->string('calling_code', 16)->nullable()->index()->after('flag_emoji')->comment('Primary international phone calling code, for example +44.');
}
if (! in_array('tld', $columns, true)) {
$table->string('tld', 16)->nullable()->index()->after('calling_code')->comment('Primary country-code top-level domain, for example .uk.');
}
if (! in_array('currency_code', $columns, true)) {
$table->char('currency_code', 3)->nullable()->index()->after('tld')->comment('Primary ISO 4217 currency code.');
}
if (! in_array('currency_name', $columns, true)) {
$table->string('currency_name')->nullable()->after('currency_code')->comment('Primary currency display name.');
}
if (! in_array('currency_symbol', $columns, true)) {
$table->string('currency_symbol', 16)->nullable()->after('currency_name')->comment('Primary currency symbol.');
}
if (! in_array('languages', $columns, true)) {
$table->json('languages')->nullable()->after('currency_symbol')->comment('Language metadata as JSON array/object.');
}
if (! in_array('timezones', $columns, true)) {
$table->json('timezones')->nullable()->after('languages')->comment('Timezone metadata as JSON array.');
}
if (! in_array('latitude', $columns, true)) {
$table->decimal('latitude', 10, 7)->nullable()->after('timezones')->comment('Approximate latitude for maps and geo grouping.');
}
if (! in_array('longitude', $columns, true)) {
$table->decimal('longitude', 10, 7)->nullable()->after('latitude')->comment('Approximate longitude for maps and geo grouping.');
}
if (! in_array('flag_svg_url', $columns, true)) {
$table->string('flag_svg_url')->nullable()->after('longitude')->comment('Optional externally hosted SVG flag URL.');
}
if (! in_array('flag_png_url', $columns, true)) {
$table->string('flag_png_url')->nullable()->after('flag_svg_url')->comment('Optional externally hosted PNG flag URL.');
}
if (! in_array('ioc_code', $columns, true)) {
$table->string('ioc_code', 8)->nullable()->index()->after('flag_png_url')->comment('IOC country code where applicable.');
}
if (! in_array('fifa_code', $columns, true)) {
$table->string('fifa_code', 8)->nullable()->index()->after('ioc_code')->comment('FIFA country code where applicable.');
}
if (! in_array('postal_code_format', $columns, true)) {
$table->string('postal_code_format')->nullable()->after('fifa_code')->comment('Human-readable postal-code format/pattern.');
}
if (! in_array('address_format', $columns, true)) {
$table->text('address_format')->nullable()->after('postal_code_format')->comment('Country-specific address formatting guidance.');
}
if (! in_array('deleted_at', $columns, true)) {
$table->softDeletes()->comment('Soft deletion for retired/custom country records.');
}
});
}
/**
* Reverse enterprise ISO 3166 support fields.
*/
public function down(): void
{
Schema::table('countries', function (Blueprint $table): void {
foreach ([
'deleted_at',
'address_format',
'postal_code_format',
'fifa_code',
'ioc_code',
'flag_png_url',
'flag_svg_url',
'longitude',
'latitude',
'timezones',
'languages',
'currency_symbol',
'currency_name',
'currency_code',
'tld',
'calling_code',
'un_member',
'sovereignty_status',
'intermediate_region',
'continent',
'capital',
'native_name',
] as $column) {
if (Schema::hasColumn('countries', $column)) {
$table->dropColumn($column);
}
}
});
}
};