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

[5.8] Changed Collection::firstWhere signature to be the same as Collection::where #26261

Merged
merged 1 commit into from
Oct 26, 2018

Conversation

axlon
Copy link
Contributor

@axlon axlon commented Oct 26, 2018

This small PR makes the collection convenience method firstWhere work the same way as the where function does by making the second parameter optional.

Image we have a Post model with a boolean property published, if we wanted to retrieve the first published post we could do this

$collection->where('published')->first()

But if we use the convenience method firstWhere

# We have to pass true here, because the second argument is required
$collection->firstWhere('published', true)

With this PR the second argument to firstWhere is no longer required and boolean checks can be performed the same way as with the where function.

This PR is the same as #26260, but targets and branches from the correct branch.

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