sokil/php-isocodes-db-only
Database-only package for sokil/php-isocodes: ISO 3166-1 countries, 3166-2 subdivisions, 639-3 languages, 4217 currencies, and 15924 scripts. No i18n/localized names. Updated monthly (2nd day).
countries). Ideal for modular architectures where ISO data is a shared dependency.Country model with iso_alpha2 as primary key).Rule::isoCountry()).localization package for region-specific content./api/countries/{code}).countries (ISO 3166-1): iso_alpha2, iso_alpha3, name, numeric.subdivisions (ISO 3166-2): country_code, subdivision_code, name.languages (ISO 639-3): iso_639_3, name.currencies (ISO 4217): iso_4217, name, symbol.Schema::create() and seeders to populate data. Example:
Schema::create('countries', function (Blueprint $table) {
$table->char('iso_alpha2', 2)->primary();
$table->char('iso_alpha3', 3)->unique();
$table->string('name');
$table->string('numeric')->unique();
});
user table’s country column) for read-heavy workloads.hasMany for subdivisions under countries.Rule class for ISO-specific validation.| Risk Area | Mitigation Strategy |
|---|---|
| Schema Conflicts | Compare the package’s schema with existing DB. Use Laravel’s Schema::hasTable() checks in migrations. |
| Data Freshness | Monthly updates may lag. Implement a cron job to auto-pull updates via GitHub releases or a custom API wrapper. |
| Localization Gaps | This package lacks i18n. Plan to either: (1) Use php-isocodes-db-i18n later, or (2) Build a translation layer (e.g., translations pivot table). |
| Performance Bottlenecks | Large datasets (e.g., subdivisions) may bloat queries. Optimize with indexes and caching (e.g., Cache::remember). |
| Dependency Bloat | The package is lightweight (~1MB), but sokil/php-isocodes (core library) may add ~50KB. Audit for unused features. |
| Breaking Changes | ISO standards evolve (e.g., new countries). Monitor ISO’s official updates and test migrations. |
is_eu_member flag or custom subdivisions)?countries table or packages like laravel-countries.iso_alpha2)./api/countries/{code}).FormRequest for ISO code validation.Stripe, PayPal (e.g., currency field in orders).geoip2) for subdivision-level data.laravel-localization for region-specific content (e.g., app/{locale}).countries, subdivisions) and non-critical (e.g., scripts).countries:
Schema::create('countries', function (Blueprint $table) {
$table->char('iso_alpha2', 2)->primary();
$table->char('iso_alpha3', 3)->unique();
$table->string('name');
$table->string('numeric')->unique();
$table->timestamps(); // Optional: for audit logs
});
countries and languages tables. Build Eloquent models and basic queries.
// app/Models/Country.php
class Country extends Model {
protected $primaryKey = 'iso_alpha2';
public $timestamps = false;
}
subdivisions with nested relationships (e.g., US states under US).
// app/Models/Subdivision.php
class Subdivision extends Model {
public function country() {
return $this->belongsTo(Country::class, 'country_code', 'iso_alpha2');
}
}
// app/Services/IsoCodeService.php
class IsoCodeService {
public function validateCountryCode(string $code): bool {
return Country::where('iso_alpha2', $code)->exists();
}
}
use Illuminate\Validation\Rule;
Rule::macro('isoCountry', function ($field) {
return Rule::exists('countries', 'iso_alpha2')->whereColumn(
$field, 'iso_alpha2'
);
});
iso_alpha2, iso_alpha3, and name fields are indexed for performance.How can I help you explore Laravel packages today?