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.4] fix eloquent collection contains issue #19568

Merged
merged 3 commits into from
Jun 12, 2017
Merged

Conversation

storyn26383
Copy link
Contributor

@storyn26383 storyn26383 commented Jun 12, 2017

I think this pull request can fix below issue:

$post = Post::create(['id' => 1]);
$comment = Comment::create(['id' => 1]);

$collection = new EloquentCollection([$post]);

$collection->contains($comment); // expect is false, but true given

if ($key instanceof Model) {
return parent::contains(function ($model) use ($key) {
return $model->getKey() == $key->getKey() &&
get_class($model) == get_class($key);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use $model->is($key) instead if possible? That has some additional checks such as connection as well!

Copy link
Contributor Author

@storyn26383 storyn26383 Jun 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for advice, much better now 😜

@taylorotwell taylorotwell merged commit 3cde539 into laravel:5.4 Jun 12, 2017
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.

3 participants