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

Php Enum Laravel Package

paillechat/php-enum

PHP 7+ enum library: define enums by extending Enum and declaring constants, then instantiate via static named calls (IssueType::ONE()). Instances are strict-equal singletons, work with in_array/type hints, and can convert to/from names.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Type Safety & Code Clarity: Enables strict typing for domain-specific constants (e.g., UserRole::ADMIN, OrderStatus::PENDING), reducing runtime errors and improving IDE autocompletion.
  • Laravel Integration: Aligns with Laravel’s evolving PHP 8+ support (e.g., native enums in PHP 8.1), offering a backward-compatible solution for legacy projects or teams avoiding PHP 8.
  • API/DB Layer Abstraction: Simplifies serialization/deserialization (e.g., converting OrderStatus::PENDING to "pending" for APIs or database storage) via createByName().
  • Roadmap for Native Enums: Acts as a stopgap until PHP 8.1’s native enums are widely adopted, with minimal migration effort when upgrading.
  • Build vs. Buy: Avoids reinventing enum logic; leverages a battle-tested, MIT-licensed package with minimal maintenance overhead.

When to Consider This Package

  • Avoid if:
    • Using PHP 8.1+: Native enums are superior (better performance, built-in features).
    • Project requires active maintenance: Last release was 2018; consider alternatives like myclabs/php-enum (more stars, recent updates).
    • Need advanced features: No support for backends, methods, or computed properties (unlike PHP 8.1 enums).
    • Performance-critical: Overhead of reflection-based enum instantiation (though negligible for most use cases).
  • Consider if:
    • Supporting PHP 7.4–8.0 with strict typing.
    • Migrating from magic strings/constants (e.g., "active"Status::ACTIVE).
    • Requiring simple, named enums without complex logic.
    • Team lacks PHP 8.1 upgrade bandwidth but needs enum-like behavior.

How to Pitch It (Stakeholders)

For Executives: "This package lets us enforce strict, self-documenting constants (e.g., PaymentStatus::PENDING) across our Laravel app, reducing bugs from magic strings. It’s a lightweight, MIT-licensed solution that works today—with minimal effort to upgrade to PHP 8.1’s native enums later. Think of it as ‘type safety on steroids’ for our domain logic, with zero operational overhead."

For Engineers: *"We’re adding a dependency that:

  1. Replaces magic strings with type-safe enums (e.g., UserRole::ADMIN instead of 'admin').
  2. Works with Laravel’s ecosystem: Serializes to/from strings for APIs/databases via createByName().
  3. Future-proofs: Almost identical syntax to PHP 8.1’s native enums, so migration later is trivial.
  4. Zero maintenance: MIT-licensed, no active development needed (but easy to swap if we upgrade PHP). Downside: Last updated in 2018, but the core functionality is stable and matches our needs."*

For Developers: *"This lets you:

  • Autocomplete enums in your IDE (e.g., Status:: → shows PENDING, APPROVED).
  • Compare enums strictly: $status === Status::PENDING works out of the box.
  • Convert to/from strings easily: Status::createByName('PENDING') for APIs. Example:
// Before: if ($status == 'pending') { ... } // 🚨 Magic string!
// After: if ($status === Status::PENDING) { ... } // ✅ Type-safe!
```*
*Tradeoff*: Not PHP 8.1’s native enums, but it’s a drop-in replacement for now."*
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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky