bipinkareparambil / laravel-where-like-any
Adds whereLikeAny, whereLikeAll, whereNotLikeAny, whereNotLikeAll (and or* variants) to Laravel's query builder.
Package info
github.com/bipinks/laravel-where-like-any
pkg:composer/bipinkareparambil/laravel-where-like-any
Requires
- php: ^8.2
- illuminate/database: ^11.0|^12.0|^13.0
- illuminate/support: ^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^9.0|^10.0
- phpunit/phpunit: ^10.5|^11.0
README
Adds symmetric "one column, multiple patterns" LIKE filtering to Laravel's query builder, complementing the built-in whereAny / whereAll (which handle "multiple columns, one pattern").
Install
composer require bipinkareparambil/laravel-where-like-any
The service provider auto-registers. The new methods are available on Illuminate\Database\Query\Builder and, by extension, Eloquent builders.
Methods
| Method | SQL |
|---|---|
whereLikeAny($col, $values) |
(col LIKE ? OR col LIKE ?) |
whereNotLikeAny($col, $values) |
(col NOT LIKE ? AND col NOT LIKE ?) |
whereLikeAll($col, $values) |
(col LIKE ? AND col LIKE ?) |
whereNotLikeAll($col, $values) |
(col NOT LIKE ? OR col NOT LIKE ?) |
Plus or variants: orWhereLikeAny, orWhereNotLikeAny, orWhereLikeAll, orWhereNotLikeAll.
All methods accept a $caseSensitive flag. Under the hood each call delegates to whereLike, so MySQL like binary, Postgres ilike, and SQLite glob all work automatically — no grammar changes.
Usage
// Match any pattern User::whereLikeAny('name', ['%john%', '%jane%'])->get(); // Match all patterns User::whereLikeAll('bio', ['%laravel%', '%php%'])->get(); // Exclude any pattern User::whereNotLikeAny('email', ['%spam%', '%temp%'])->get(); // Case-sensitive on MySQL User::whereLikeAny('name', ['%John%'], caseSensitive: true)->get();
Negation semantics (De Morgan's)
whereNotLikeAnynegates "match any" → flipsORtoAND.whereNotLikeAllnegates "match all" → flipsANDtoOR.
Tests
composer install vendor/bin/phpunit
Why a package?
Originally proposed to Laravel core in laravel/framework#59725. Released as a package per maintainer preference to keep the core surface area small.
License
MIT