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

[8.x] Handle collection creation around a single enum #42839

Merged
merged 3 commits into from
Jun 17, 2022

Conversation

tontonsb
Copy link
Contributor

Current behaviour:

$c = collect(SomeEnum::myCase);
$c->items; // ['name' => 'myCase']

$c = collect(BackedEnum::myCase);
$c->items; // ['name' => 'myCase', 'value' => BackedEnum::myCase->value]

In my opinion it is a bug, it is natural to expect collect(SomeEnum::myCase) to produce a single item collection containing the item itself like it does with collect('mystring') instead of unwrapping it and changing the item count based on whether it's a backed enum.

This PR changes the behaviour so that:

$c = collect(SomeEnum::myCase);
$c->items; // [SomeEnum::myCase]

@taylorotwell taylorotwell merged commit e404e88 into laravel:8.x Jun 17, 2022
@GrahamCampbell GrahamCampbell changed the title Handle collection creation around a single enum [8.x] Handle collection creation around a single enum Jun 17, 2022
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.

None yet

2 participants