Skip to content

fix: implement QueryBuilder search across searchable columns - #5

Merged
fadymondy merged 1 commit into
masterfrom
fix/search
Sep 15, 2026
Merged

fadymondy merged 1 commit into
masterfrom
fix/search

Conversation

@fadymondy

Copy link
Copy Markdown
Contributor

Problem

QueryBuilder::search() had no effect: applySearch() was an empty stub.

Changes

  • New searchable(array|string $columns) to register the columns to search (+ getSearchableColumns()).
  • applySearch() trims the term and matches %term% with LIKE, OR'd across columns inside a nested where group (so it doesn't break other constraints). Blank/null term, or no searchable columns, is a no-op.
  • %, _ and \ in the term are escaped, with an explicit ESCAPE '\' clause so escaping works on sqlite/pgsql as well as mysql.
  • Dot-notation columns whose prefix resolves to Eloquent relations (e.g. author.name) are searched via orWhereHas; other dotted values are treated as table-qualified columns.

Tests

New tests/Feature/QueryBuilderSearchTest.php (sqlite): matching, blank no-op, no columns no-op, multi-column OR, nesting with an outer constraint, escaping of %, _, \, and relation search. Full suite: 126 passed. Pint clean.

🤖 Generated with Claude Code

search() previously had no effect because applySearch() was empty.

- Add searchable(array|string) to register columns to search.
- applySearch() matches the trimmed term with a contains LIKE, OR'd across
  columns inside a nested where group; blank/null term is a no-op.
- Escape %, _ and \ in the term and use an explicit ESCAPE '\' clause so
  escaping works on sqlite/pgsql as well as mysql.
- Dot-notation columns whose prefix is a relation (e.g. author.name) are
  searched via orWhereHas; otherwise treated as a plain/qualified column.
- Add feature tests for matching, blank no-op, multi-column OR, nesting,
  escaping and relation search.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 9ca61d44-2e4a-48c6-8bef-f7d912452c83

📥 Commits

Reviewing files that changed from the base of the PR and between fdd01ee and 78ce7c5.

📒 Files selected for processing (2)
  • src/QueryBuilder.php
  • tests/Feature/QueryBuilderSearchTest.php

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@fadymondy
fadymondy merged commit 4aa3c55 into master Sep 15, 2026
5 checks passed
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