Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(collection): add "contains any" filter #56091

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

Open
wants to merge 3 commits into
base: 12.x
Choose a base branch
from

Conversation

sawirricardo
Copy link

@sawirricardo sawirricardo commented Jun 20, 2025

// before if we want to check 1 or 3 exists...
$collection = collect([1,3,5]);
$collection->contains(1) && $collection->contains(3);

//after
collect([1,3,5])->containsAny([1,3]); // return true
collect([2,4])->containsAny([2,5]); // return true

// real world use case example
$user->abilities->add(['*']);
$user2->abilities->add(['server:create']);

function checkAbility($user): bool
{
   return $user->abilities->containsAny(['*', 'server:create']);
}

Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@sawirricardo sawirricardo marked this pull request as ready for review June 20, 2025 13:31
@shaedrich
Copy link
Contributor

What about

collect([1,3,5])->intersect([1,3])->isNotEmpty(); // return true

?

@sawirricardo
Copy link
Author

possible too I think! Nice to know more alternatives for this case @shaedrich

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