Skip to content

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

Merged
taylorotwell merged 3 commits into
laravel:8.xfrom
tontonsb:patch-25
Jun 17, 2022
Merged

[8.x] Handle collection creation around a single enum#42839
taylorotwell merged 3 commits into
laravel:8.xfrom
tontonsb:patch-25

Conversation

@tontonsb

Copy link
Copy Markdown
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.

2 participants