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

Projects
None yet
2 participants
@axlon
Copy link
Contributor

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.

@taylorotwell taylorotwell merged commit 5d40515 into laravel:master Oct 26, 2018

1 of 2 checks passed

continuous-integration/travis-ci/pr The Travis CI build failed
Details
continuous-integration/styleci/pr The analysis has passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.