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

Request: functions to values or names from enum. #5

Closed
CamilleScholtz opened this issue Feb 17, 2023 · 2 comments
Closed

Request: functions to values or names from enum. #5

CamilleScholtz opened this issue Feb 17, 2023 · 2 comments

Comments

@CamilleScholtz
Copy link

The following migration rule does not work because cases() returns an array of enum objects rather than an array of strings:

    $table->enum('status', TransactionStatus::cases());

names() and values() functions would be nice in this case, they would return an array with strings.

Example:

    public static function names(): array
    {
        return array_column(self::cases(), 'name');
    }
@henzeb
Copy link
Owner

henzeb commented Feb 19, 2023

This is already possible with Subset.

$table->enum('status', TransactionStatus::of()->names());

be aware though that migrations should reflect the state after this migration ran.

@CamilleScholtz
Copy link
Author

I overlooked that one, seems like a solution!

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

No branches or pull requests

2 participants