Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to customize display name for select based on enums #2776

Merged
merged 1 commit into from
Dec 20, 2023

Conversation

czernika
Copy link
Contributor

Proposed Changes

This PR gives option to change displayed values for Select Field based on Enum

// Enum
enum RoleNames: string
{
    case Admin = 'admin';
    case User = 'user';

    public function label(): string
    {
        return match ($this) {
            self::Admin => 'Administrator',
            self::User => 'Regular user',
        };
    }
}

// Layout
Select::make('fromEnum')
   ->fromEnum(RoleNames::class, 'label'), // pass second option as method name

This will generate values based on label method

Снимок экрана от 2023-12-20 12-10-04

@tabuna tabuna merged commit 25a9d04 into orchidsoftware:master Dec 20, 2023
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants