Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Enum Laravel Package

elao/enum

Opinionated extensions for PHP 8.1+ native enums with readable labels, flag/bitmask enums, and extra values. Includes integrations for Symfony (Forms, HTTP Kernel arg resolver, Translation, VarDumper), Doctrine ORM/ODM, and Faker.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Standardization of Enums Across Codebase: Replace ad-hoc string constants or magic values with strongly-typed, self-documenting enums, reducing bugs from invalid values.
  • Framework Integration: Accelerate development in Symfony/Laravel by leveraging built-in integrations (e.g., form types, validation, Doctrine ORM).
  • Internationalization (i18n) & Localization: Use ReadableEnum traits to auto-generate translated labels (e.g., suit.hearts → "Cœurs" in French) without manual YAML/JSON files.
  • API Contracts: Enforce consistent enum serialization/deserialization in JSON APIs (e.g., #[AsArray] for API responses).
  • Migration from Legacy Systems: Gradually replace old define('STATUS_PENDING', 1) patterns with modern enums while maintaining backward compatibility.
  • Performance Optimization: Cache enum instances (via #[CacheableEnum]) to reduce reflection overhead in high-traffic applications.
  • Developer Experience (DX): Reduce boilerplate for common enum patterns (e.g., #[BackedEnum], #[SearchableEnum] for database queries).

Roadmap Alignment:

  • Enables self-service data modeling for non-engineers (e.g., business analysts defining enums via UI).
  • Supports feature flags for enum-based toggles (e.g., #[FeatureFlaggedEnum]).
  • Future-proofs for PHP 9+ and Symfony 7+ without major refactoring.

When to Consider This Package

Adopt if:

  • Your team uses Symfony 6.4+ or Laravel (via Symfony bridge) and PHP 8.4+.
  • You need enums with business logic (e.g., validation, i18n, or database queries) beyond native PHP enums.
  • Your API or forms rely on consistent, type-safe labels (e.g., dropdowns, error messages).
  • You’re migrating from legacy constants or database-driven enums (e.g., status table) to code-first enums.
  • Your project prioritizes maintainability over minimalism (e.g., 30+ enums with shared traits).

Look elsewhere if:

  • You’re using PHP <8.4 or Symfony <6.4 (native enums suffice).
  • Your enums are simple (e.g., enum Color { Red, Green }) with no extra behavior.
  • You prefer minimal dependencies (this package adds ~10 traits/interfaces).
  • Your team lacks Symfony/Laravel familiarity (native enums are simpler to debug).
  • You need runtime enum generation (e.g., dynamic enums from a database).

How to Pitch It (Stakeholders)

For Executives: "This package lets us replace error-prone string constants with self-documenting, type-safe enums—cutting bugs in forms, APIs, and databases by 30%+ while making our codebase easier to maintain. For example, a PaymentStatus enum auto-generates translated labels for customer support tools and enforces valid states in our Laravel backend. It’s a low-risk upgrade (MIT license, active maintenance) that pays dividends in developer velocity and data integrity."

For Engineers: *"Elao’s enums extend PHP 8.4’s native enums with Symfony/Laravel integrations:

  • Forms: Auto-map enums to <select> fields with #[FormEnum].
  • Validation: Use #[Assert\ValidEnum] for Symfony Validator.
  • i18n: Define #[ReadableEnum(prefix: 'order.')] once, get translations everywhere.
  • Doctrine: Query enums directly (where status = OrderStatus::PENDING).
  • APIs: Serialize as arrays (#[AsArray]) or custom formats.

It’s like Laravel’s Str or Collection for enums—opinionated but battle-tested. Migration is gradual: start with critical enums (e.g., UserRole, OrderStatus), then expand."*

For Architects: *"Key tradeoffs:

  • Pros: Reduces boilerplate for common patterns (e.g., searchable enums for Eloquent), integrates with Symfony’s ecosystem (e.g., Messenger, Serializer).
  • Cons: Tight coupling to Symfony (though Laravel support exists via symfony/options-resolver). If you’re all-in on Symfony 6.4+, this is a no-brainer for consistency.
  • Alternatives: Native enums + manual traits (more work) or spatie/laravel-enum (less framework integration).

Recommend piloting with 2–3 high-impact enums (e.g., PaymentMethod, SubscriptionPlan) to validate DX before full adoption."*

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver