Skip to content

Fix collection value() method to properly handle falsy values (issue … #54966

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

Conversation

phadaphunk
Copy link

@phadaphunk phadaphunk commented Mar 10, 2025

close #54910

I moved this from targeting 12.x as @taylorotwell marked it as a breaking change.

This PR fixes issue #54910 where the collection value() method incorrectly skips falsy values (0, false, empty string) in the first element.

The current implementation uses firstWhere() with loose comparison, causing it to skip over the first element when the requested value is 0, false, or an empty string.

This change modifies the value() method to use first() instead, ensuring it always returns the value from the first element regardless of whether that value is "falsy".

I don't think it should be considered a breaking change since it really seems to be a bug in the intended behaviour and that this fix is more in line the documentation.

@taylorotwell
Copy link
Member

Since this is almost one year away let's revisit maybe in December.

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