prinsfrank/standards
Daily-updated PHP 8.1+ enum collection of international standards (ISO, IANA, SIX, Library of Congress, etc.). Easy Composer install, strong typing for codes like countries, currencies, languages, and more—kept current via automated upstream sync.
Illuminate\Support\Enum). This reduces runtime errors by validating inputs early (e.g., country codes, currencies).CountryAlpha2 ↔ CountryAlpha3 ↔ Currency) mirror real-world relationships, making it ideal for Laravel applications requiring geographic, linguistic, or financial data modeling (e.g., e-commerce, localization, or compliance systems).CountryAlpha2 $country in method signatures), improving IDE autocompletion and reducing ambiguity in documentation.app()->bind(CountryAlpha2::class, fn() => CountryAlpha2::from('US'))).country_code) to enums (e.g., CountryAlpha2).CountryAlpha2::US → 'US'), which map cleanly to database ENUM or VARCHAR columns.Db::raw() to create ENUM columns (MySQL) or validate against enum values in unique/foreignKey constraints.Rule::in(array_column(CountryAlpha2::cases(), 'value'))) or custom rules extending Illuminate\Validation\Rule.composer.json (e.g., ^1.0).symfony/options-resolver used internally). Test with composer why-not and composer why.CountrySubdivision) may require custom handling for regions not covered by ISO standards.formatNumber() rely on user-provided locales; ensure your app handles fallback locales gracefully.CountryAlpha2 ↔ CountryNumeric) be frequent in hot paths?CountryAlpha3::NLD->getCurrencies()) in CI?CountryAlpha2::CS) that need handling?CountryAlpha2::XX)?spatie/laravel-enum for additional utilities (e.g., database casting).prinsfrank/standards enums in Illuminate\Validation\Rules\Enum or custom rules.laravel-localization or spatie/laravel-translatable for language/country-specific content.JsonSerializable or custom JSON encoders (e.g., Illuminate\Support\Str::upper() for CountryAlpha2).ENUM columns for backed values (e.g., country_code ENUM('US', 'CA', 'GB')).TEXT columns with checks or DOMAIN constraints.TEXT with application-level validation.CountryAlpha2::cases()) in Redis or Laravel’s cache driver to avoid repeated instantiation.country_code → CountryAlpha2 attribute).country: "US" → country: CountryAlpha2::US).use PrinsFrank\Standards\Country\HasCountryAlpha2;
class User extends Model {
use HasCountryAlpha2;
}
ENUM columns or backfill data).Rule::in(CountryAlpha2::cases())).if ($order->country->isMemberOf(EU::class))).getCountryCode() returning a string while storing CountryAlpha2).class Order extends Model {
protected $country;
public function getCountryCode(): string {
return $this->country?->value ?? null;
}
public function setCountryCode(string $code): void {
$this->country = CountryAlpha2::from($code);
}
}
CountryAlpha2::tryFrom('XX')).CountryAlpha2::UNDEFINED).$validator = Validator::make($request->all(), [
'country' => ['required', Rule::in(array_column(CountryAlpha2::cases(), 'value'))],
]);
use Illuminate\Database\Eloquent\Casts\Attribute;
class User extends Model {
protected function country(): Attribute {
return Attribute::make(
get: fn ($value) => CountryAlpha2::from($value),
set: fn ($value) => $value?->value,
);
}
}
CountryAlpha3::NLD->getCurrencies()).CountryAlpha2::US->value).JsonSerializable or custom encoders for complex enums (e.g., CountryAlpha3 with related data).update-spec-country.yml).How can I help you explore Laravel packages today?