feat(like): add or and negated contains variants - #1
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
LikeOperatorcould only add a positive, AND joined contains clause. Filters that OR several keywords together, or exclude keywords withNOT LIKE, still had to be written by hand withwhereRaw(), and that is exactly where the MySQLESCAPEbug tends to come back.This adds:
Design
The two new optional parameters copy the signature of Laravel's own
whereLike($column, $value, $caseSensitive, $boolean = 'and', $not = false), and the three shortcuts copy itsorWhereLike/whereNotLike/orWhereNotLikenaming (prefixed like the existingapply*methods). Laravel developers already know that shape, the change is fully backwards compatible, and the shortcuts keep call sites readable without a pair of positional flags.applyContainsOnDate()gets the parameters for free because both methods now share one private builder, but no extra shortcuts, to keep the surface small.$booleanends up concatenated into the SQL by the grammar, so anything other thanandoror(case insensitive) throwsInvalidArgumentExceptioninstead of producing broken SQL.Escaping, operator choice (
ILIKE/NOT ILIKEon PostgreSQL) and the per driverESCAPEclause are unchanged and shared by every variant.NULL semantics
Unchanged and now documented:
NULL NOT LIKE '%x%'isNULL, so aNULLcolumn is excluded by the negated variants just as by the positive ones. A test pins this down, and the README shows thewhereNull()plusorApplyNotContains()grouping for callers that want those rows kept.Tests
New integration tests cover OR joining, OR grouping inside a closure, NOT, OR NOT, the raw
$boolean/$notarguments, the date variant, theNULLbehaviour and the invalid boolean. The negated variant is checked with decoy rows for%(100% remote),_(data_engineer) and\. The suite passes on SQLite, MySQL 8 and PostgreSQL 16, along with PHPStan, Pint, Rector and type coverage.The workbench
documentstable gains a nullablesummarycolumn for theNULLtests.