Skip to content

[12.x] Add BackedEnum support for session keys#58241

Merged
taylorotwell merged 1 commit intolaravel:12.xfrom
ahinkle:session-key-backed-enum
Jan 1, 2026
Merged

[12.x] Add BackedEnum support for session keys#58241
taylorotwell merged 1 commit intolaravel:12.xfrom
ahinkle:session-key-backed-enum

Conversation

@ahinkle
Copy link
Copy Markdown
Contributor

@ahinkle ahinkle commented Dec 31, 2025

This PR adds enum support for Session keys. Laravel already handles BackedEnums gracefully in Gate, Queue, Cache, RateLimiter, and elsewhere - this pattern follows the same.

If you're managing a multi-step checkout flow across several components, you probably have something like:

enum CheckoutSession: string
{
    case Cart = 'checkout.cart';
    case ShippingAddress = 'checkout.shipping_address';
    case PaymentMethod = 'checkout.payment_method';
}

Right now you have to do ->value everywhere:

session()->put(CheckoutSession::Cart->value, $items);
session()->get(CheckoutSession::Cart->value);

This PR lets you drop the ->value:

session()->put(CheckoutSession::Cart, $items);
session()->get(CheckoutSession::Cart);

Uses enum_value() to normalize keys, same pattern as the rest of the framework.

@taylorotwell taylorotwell merged commit 5a8d03e into laravel:12.x Jan 1, 2026
72 checks passed
DarkGhostHunter pushed a commit to DarkGhostHunter/laravel-framework that referenced this pull request Jan 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants