Skip to content

feat(like): add starts with variants - #3

Merged
danielebarbaro merged 4 commits into
mainfrom
feat/starts-with
Nov 21, 2026
Merged

danielebarbaro merged 4 commits into
mainfrom
feat/starts-with

Conversation

@danielebarbaro

Copy link
Copy Markdown
Contributor

LikeOperator only offers "contains" searches. An autocomplete that needs a prefix match (typing "ro" should list "Roma" before names that merely include "ro") has to hand write whereRaw() with its own escaping and ESCAPE clause.

This adds prefix matching with the same shape as the contains family: wildcards in the term are literal, the term is always bound, and the operator (LIKE or ILIKE) and ESCAPE clause are picked per driver. The private applyPattern() now receives the finished pattern instead of the raw term, which is the only change to shared code.

New public methods:

  • startsWithPattern(string $term): string
  • applyStartsWith(Builder $query, string $column, string $term, string $boolean = 'and', bool $not = false): void
  • orApplyStartsWith(), applyNotStartsWith(), orApplyNotStartsWith()
$towns = Town::query();
LikeOperator::applyStartsWith($towns, 'name', $term);
$towns->limit(20)->get();

The existing methods are unchanged. README, CHANGELOG (Unreleased) and the Boost guidelines are updated, and the new tests run on SQLite, MySQL 8 and PostgreSQL 16.

@danielebarbaro
danielebarbaro merged commit 0a49112 into main Nov 21, 2026
24 checks passed
@danielebarbaro
danielebarbaro deleted the feat/starts-with branch November 21, 2026 18:33
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.

1 participant