# Laravel Enums

> Backed enums with labels and business logic. Use when defining or modifying enums, status values, or fixed option sets.

- **Type:** Skill
- **Install:** `agentstack add skill-leeovery-agentic-skills-laravel-enums`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [leeovery](https://agentstack.voostack.com/s/leeovery)
- **Installs:** 0
- **Category:** [Agent Skills](https://agentstack.voostack.com/c/agent-skills)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [leeovery](https://github.com/leeovery)
- **Source:** https://github.com/leeovery/agentic-skills/tree/main/laravel/skills/laravel-enums

## Install

```sh
agentstack add skill-leeovery-agentic-skills-laravel-enums
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# Laravel Enums

Enums provide type-safe, finite sets of values.

**Related guides:**
- [State Machines](../laravel-state-machines/SKILL.md) - For complex state transitions
- [Models](../laravel-models/SKILL.md) - Model casts to enums
- [DTOs](../laravel-dtos/SKILL.md) - DTOs with enum properties
- [form-requests.md](../laravel-validation/references/form-requests.md) - Enum validation

## Always Use Backed Enums

**Always use backed enums** (string or int):

```php
 'Pending Review',
            self::Completed => 'Completed',
        };
    }

    public function color(): string
    {
        return match ($this) {
            self::Pending => 'yellow',
            self::Completed => 'green',
        };
    }
}
```

```php
// Reusable trait for shared behavior across enums
trait HasLabel
{
    abstract public function label(): string;

    public static function labels(): array
    {
        return collect(self::cases())->mapWithKeys(
            fn ($enum) => [$enum->value => $enum->label()]
        )->toArray();
    }
}
```

## Business Logic in Enums

Enums can contain behavior via match expressions:

```php
enum PaymentProvider: string
{
    case Stripe = 'stripe';
    case PayPal = 'paypal';
    case Square = 'square';

    public function processingFee(int $amount): int
    {
        return match ($this) {
            self::Stripe => (int) ($amount * 0.029 + 30),
            self::PayPal => (int) ($amount * 0.034 + 30),
            self::Square => (int) ($amount * 0.026 + 10),
        };
    }

    public function supportsRefunds(): bool
    {
        return match ($this) {
            self::Stripe, self::PayPal => true,
            self::Square => false,
        };
    }
}
```

## Usage in Models

```php
protected function casts(): array
{
    return [
        'status' => OrderStatus::class,
        'payment_method' => PaymentMethod::class,
    ];
}
```

## Usage in DTOs

```php
public function __construct(
    public OrderStatus $status,
    public PaymentMethod $paymentMethod,
) {}
```

## Usage in Validation

```php
use Illuminate\Validation\Rules\Enum;

'status' => [
    'required',
    'string',
    'bail',
    new Enum(OrderStatus::class),
],
```

## Common Patterns

### Match Expressions

```php
$message = match ($order->status) {
    OrderStatus::Pending => 'Your order is pending',
    OrderStatus::Processing => 'We are processing your order',
    OrderStatus::Completed => 'Your order is complete',
    OrderStatus::Cancelled => 'Your order was cancelled',
};
```

## Queue Enum Example

```php
onQueue(Queue::Emails->value);
}
```

## Directory Structure

```
app/Enums/
├── OrderStatus.php
├── PaymentMethod.php
└── Queue.php
```

## When to Use Enums vs State Machines

**Use Enums:**
- Simple status fields
- No transition logic
- No side effects

**Use State Machines:**
- Complex state transitions with rules
- State-specific behavior
- Transition side effects

See [State Machines](../laravel-state-machines/SKILL.md) for state machines.

## Summary

**Enums provide:**
- Type safety
- Finite value sets
- Business logic encapsulation
- UI helpers (labels, colors, icons)
- IDE autocomplete

**Always use backed enums** with string or int values.

## Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [leeovery](https://github.com/leeovery)
- **Source:** [leeovery/agentic-skills](https://github.com/leeovery/agentic-skills)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/skill-leeovery-agentic-skills-laravel-enums
- Seller: https://agentstack.voostack.com/s/leeovery
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
