laravel-enums

Define backed Laravel enums with labels for type-safe option sets.

1|Updated Oct 10, 2025
One-click install
npx skills add https://github.com/nextplus896/durra-alaseel --skill laravel-enums
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: laravel-enums
Source: https://github.com/nextplus896/durra-alaseel/tree/main/.github/skills/claude-laravel/laravel-enums
Command: npx skills add https://github.com/nextplus896/durra-alaseel --skill laravel-enums

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Laravel projects often rely on primitive strings or integers to represent finite option sets, which leads to scattered validation rules and inconsistent UI labels. This skill provides backed enums with labels to enforce type safety, coherent validation, and a centralized definition of business constants.

Core Features & Use Cases

  • Backed enums with string or integer values for strong typing and compile-time checks.
  • UI-friendly labels and traits to expose human-readable names in forms and dropdowns.
  • Seamless usage in models (casts to Enum), DTOs, and validation rules, ensuring consistent handling of status or mode fields across the application.
  • Guidance on when to use enums vs state machines for complex workflows.

Quick Start

  • Create a new Enum in app/Enums with cases representing your domain values, using string backs (e.g., Pending = 'pending').
  • Cast model attributes to the enum (e.g., protected $casts = ['status' => OrderStatus::class];).
  • Retrieve UI labels via OrderStatus::labels() or $status->getLabel() when using label attributes.

Frequently Asked Questions about laravel-enums

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use Laravel enums for type-safe model casts and validation?

Laravel enums enable type-safe model casts by mapping database columns to backed enum classes in app/Enums. You define string or integer cases, cast model attributes to the enum class, and apply validation rules to ensure consistent finite option sets across your application.

What is the best way to manage status options and UI labels in Laravel without scattered strings?

Backed enums with labels centralize business constants by defining cases like Pending = 'pending' alongside UI-friendly traits. You retrieve human-readable names via methods like OrderStatus::labels() or $status->getLabel(), ensuring coherent dropdowns and consistent display across forms.

Does Laravel backed enum validation require PHP 8.1 or higher?

Yes, Laravel backed enum validation requires PHP 8.1 or higher because it leverages native enum features for strong typing and compile-time checks. Your Laravel project must meet this version prerequisite to define string or integer backed cases and apply them to DTOs and form requests.

Can I use backed enums in Laravel DTOs and form requests for finite option sets?

Yes, backed enums can be seamlessly integrated into Laravel DTOs and form requests. By applying enum validation rules and type-hinting properties, you enforce strong typing and guarantee that only valid finite option sets are accepted during data transmission and request handling.

When should I use Laravel enums vs state machines for complex workflows?

Laravel enums are ideal for enforcing type-safe, finite option sets with consistent labels, whereas state machines are better suited for managing complex workflows with conditional state transitions. Use enums for static status representation and state machines when dynamic transition logic is required.