71 lines
3.5 KiB
PHP
Executable File
71 lines
3.5 KiB
PHP
Executable File
<?php
|
|
|
|
namespace Modules\Countries\Database\Seeders;
|
|
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Carbon;
|
|
use Modules\Countries\Models\Country;
|
|
use Modules\Countries\Models\CountrySubdivision;
|
|
|
|
class IsoCountrySubdivisionsSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Seed high-value ISO 3166-2 subdivisions used by UK/US business workflows.
|
|
*
|
|
* This module is structured to import the full ISO 3166-2 data set from an approved licensed source.
|
|
* The bundled seed keeps the module useful out of the box without pretending to be the complete ISO 3166-2 catalogue.
|
|
*/
|
|
public function run(): void
|
|
{
|
|
$now = Carbon::now();
|
|
$rows = [
|
|
['country' => 'GB', 'code' => 'GB-ENG', 'name' => 'England', 'type' => 'country'],
|
|
['country' => 'GB', 'code' => 'GB-SCT', 'name' => 'Scotland', 'type' => 'country'],
|
|
['country' => 'GB', 'code' => 'GB-WLS', 'name' => 'Wales', 'type' => 'country'],
|
|
['country' => 'GB', 'code' => 'GB-NIR', 'name' => 'Northern Ireland', 'type' => 'province'],
|
|
['country' => 'US', 'code' => 'US-AL', 'name' => 'Alabama', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-AK', 'name' => 'Alaska', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-AZ', 'name' => 'Arizona', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-AR', 'name' => 'Arkansas', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-CA', 'name' => 'California', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-CO', 'name' => 'Colorado', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-CT', 'name' => 'Connecticut', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-DE', 'name' => 'Delaware', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-FL', 'name' => 'Florida', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-NY', 'name' => 'New York', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-TX', 'name' => 'Texas', 'type' => 'state'],
|
|
['country' => 'US', 'code' => 'US-WA', 'name' => 'Washington', 'type' => 'state'],
|
|
['country' => 'CA', 'code' => 'CA-AB', 'name' => 'Alberta', 'type' => 'province'],
|
|
['country' => 'CA', 'code' => 'CA-BC', 'name' => 'British Columbia', 'type' => 'province'],
|
|
['country' => 'CA', 'code' => 'CA-ON', 'name' => 'Ontario', 'type' => 'province'],
|
|
['country' => 'CA', 'code' => 'CA-QC', 'name' => 'Quebec', 'type' => 'province'],
|
|
];
|
|
|
|
foreach ($rows as $index => $row) {
|
|
$country = Country::query()->where('alpha2', $row['country'])->first();
|
|
|
|
if (! $country) {
|
|
continue;
|
|
}
|
|
|
|
CountrySubdivision::query()->updateOrCreate(
|
|
['code' => $row['code']],
|
|
[
|
|
'country_id' => $country->id,
|
|
'country_alpha2' => $country->alpha2,
|
|
'subdivision_code' => substr($row['code'], 3),
|
|
'name' => $row['name'],
|
|
'local_name' => null,
|
|
'type' => $row['type'],
|
|
'is_active' => true,
|
|
'iso_status' => 'official',
|
|
'sort_order' => $index + 1,
|
|
'last_synced_at' => $now,
|
|
'source' => 'bundled-bootstrap',
|
|
'source_version' => '2026-06-15',
|
|
],
|
|
);
|
|
}
|
|
}
|
|
}
|