Skip to content

[12.x] Add whereLike and whereNotLike methods to Collection #56112

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

Closed
wants to merge 2 commits into from

Conversation

prajan11
Copy link

This PR adds whereLike() and whereNotLike() methods to the Collection class, providing SQL-like pattern matching capabilities similar to the whereLike() method available in the query builder.

These methods allow filtering a collection by applying a LIKE or NOT LIKE pattern match to the value of a given key. The pattern supports wildcards, % (any sequence of characters) and _ (a single character), and also respects escaped wildcards (\%, \_). Optional case sensitivity is also supported via. a third parameter ($caseSensitive, defaulting to false).

Moreover, both methods support nested keys using dot notation via. data_get() helper.

Query builder and collections support various where methods (where(), whereIn(), whereBetween(), etc.). But, whereLike() was notably missing from the Collection class, which I realized while working in one of my recent Laravel projects. This PR fills that void by introducing whereLike() and whereNotLike() methods, enhancing the collection filtering using familiar SQL-style patterns.

These methods provide SQL-like pattern matching similar to the whereLike() method present in the query builder.
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.

@prajan11 prajan11 marked this pull request as ready for review June 23, 2025 13:05
@prajan11 prajan11 changed the title Add whereLike and whereNotLike methods to Collection [12.x] Add whereLike and whereNotLike methods to Collection Jun 23, 2025
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

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