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 Helper Laravel Package

oskarstark/enum-helper

Helpers for PHP 8.1+ enums: compare enum cases (equals, notEquals, equalsOneOf) and convert enums to arrays (backed and non-backed). Includes an abstract EnumTestCase to simplify testing enum behavior.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Standardizing enum usage across Laravel/PHP applications to reduce boilerplate and improve maintainability.
  • Enabling domain-driven design (DDD) by allowing clean, expressive enum methods (e.g., isNice()) that encapsulate business logic.
  • Accelerating API development by simplifying enum-to-array conversions for JSON responses, form validation, or configuration.
  • Improving testability with the EnumTestCase abstract class, reducing flakiness in test suites.
  • Build vs. Buy: Avoid reinventing enum utilities (e.g., comparison logic, array conversion) when a lightweight, MIT-licensed package exists.
  • Roadmap: Prioritize features requiring enum comparisons (e.g., role-based access, state machines) or serialization (e.g., API payloads).

When to Consider This Package

  • Adopt if:

    • Your Laravel/PHP codebase uses PHP 8.1+ enums and needs reusable comparison/serialization logic.
    • You’re building domain models where enums represent states, categories, or permissions (e.g., UserRole, OrderStatus).
    • Your team wants to reduce boilerplate for enum-to-array conversions (e.g., for API responses or form inputs).
    • You’re writing tests for enums and want a consistent EnumTestCase base class.
    • You prefer lightweight, trait-based solutions over heavy frameworks (e.g., Doctrine Enums).
  • Look elsewhere if:

    • You’re using PHP < 8.1 (this package requires PHP 8.1+).
    • Your enums are trivial (no need for comparisons/serialization).
    • You need advanced enum features (e.g., inheritance, complex backends) and prefer a full-fledged library like MyCLabs/Enum.
    • Your team already has mature enum patterns or internal utilities.
    • You’re working in a performance-critical context (this is a thin wrapper; overhead is negligible but exists).

How to Pitch It (Stakeholders)

For Executives: "This package lets us write cleaner, more maintainable code for enums—common in our Laravel apps—without reinventing the wheel. It adds two simple traits for comparing enums (e.g., checking if a UserRole is ADMIN) and converting them to arrays (for APIs/forms), plus a test helper to speed up QA. It’s a 10-minute setup with long-term payoffs in readability and developer velocity. MIT license means no vendor lock-in."

For Engineers: *"Need to compare enums or serialize them to arrays? This package gives you:

  • Comparable trait: equals(), notEquals(), equalsOneOf() for clean logic (e.g., if ($status->isActive())).
  • ToArray trait: One-liner for API responses or form inputs (works for both backed/non-backed enums).
  • EnumTestCase: Abstract base class to DRY up enum tests. It’s zero-config, PHP 8.1+, and MIT-licensed. Let’s use it for new enums and migrate existing ones where it saves time."*
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