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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] adds Str::containsAll() method #28806

merged 2 commits into from Jun 12, 2019


None yet
3 participants
Copy link

commented Jun 11, 2019

Hi everyone,

As discussed here #28688 and #28695 - in order to avoid a breaking change, I abstracted it into a new method called containsAll() and I am using contains() to check whether the value is contained inside the string.

Every now and then I run into a dilemma where I want to check if an array of values is contained within a string.

This adds the functionality to check for all array values inside a string.

Check out the tests to see all the supported scenarios.

I hope you guys find this useful, too 馃檪


* @param string|array $needles
* @return bool
public static function containsAll($haystack, $needles)

This comment has been minimized.

Copy link

timacdonald Jun 12, 2019


I'd would think this could explicitly require an array for $needles. Otherwise you would just use Str::contains() for a single item.

i.e. I'm not sure Str::containsAll($names, 'Tim'); makes sense.

This comment has been minimized.

Copy link

Chris1904 Jun 12, 2019

Author Contributor

Thanks for the feedback, Tim. I have asked myself the same question on whether a string should or should not be allowed. I thought it wouldn't "hurt" to keep the functionality and possibly could come in handy at times.

But you're right; logically, Str::contains() would be a more suitable call for that.

Definitely open for a discussion here on whether to keep or to remove it!

@taylorotwell taylorotwell merged commit a986126 into laravel:5.8 Jun 12, 2019

1 check was pending

continuous-integration/styleci/pr The analysis is running

@ahinkle ahinkle referenced this pull request Jun 12, 2019


[5.8] Str::containsAll() #5231

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can鈥檛 perform that action at this time.