From ec0f372fe0ce3a04e1e710611b3925fb3f62ffbf Mon Sep 17 00:00:00 2001 From: mmachatschek Date: Mon, 3 Mar 2025 10:01:32 +0100 Subject: [PATCH 1/7] fix: whereNotLike misses the not in the sql query --- src/Query/GrammarWhere.php | 8 ++++---- tests/Query/WhereTest.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/Query/GrammarWhere.php b/src/Query/GrammarWhere.php index 0c792b9..3dc98d0 100644 --- a/src/Query/GrammarWhere.php +++ b/src/Query/GrammarWhere.php @@ -50,10 +50,10 @@ public function whereAny(Builder $query, $where): string */ public function whereLike(Builder $query, $where): string { - return match ($where['caseSensitive']) { - true => "{$this->wrap($where['column'])} like {$this->parameter($where['value'])}", - false => "{$this->wrap($where['column'])} ilike {$this->parameter($where['value'])}", - }; + $operator = $where['not'] ? 'not ' : ''; + $operator .= $where['caseSensitive'] ? 'like' : 'ilike'; + + return "{$this->wrap($where['column'])} {$operator} {$this->parameter($where['value'])}"; } /** diff --git a/tests/Query/WhereTest.php b/tests/Query/WhereTest.php index 7c7de50..a3a5549 100644 --- a/tests/Query/WhereTest.php +++ b/tests/Query/WhereTest.php @@ -108,6 +108,24 @@ public function testOrWhereLike(): void ); } + public function testOrWhereNotLike(): void + { + $this->getConnection()->unprepared('CREATE TABLE example (str text)'); + + $queries = $this->withQueryLog(function (): void { + $this->getConnection()->table('example')->orWhereNotLike('str', 'ZsbBUJmR')->orWhereNotLike('str', '7Cc1Uf8t')->get(); + $this->getConnection()->table('example')->orWhereNotLike('str', 'OamekKIC', true)->orWhereNotLike('str', 'HmC3xURl', true)->get(); + }); + $this->assertEquals( + ['select * from "example" where "str" not ilike ? or "str" not ilike ?', 'select * from "example" where "str" not like ? or "str" not like ?'], + array_column($queries, 'query'), + ); + $this->assertEquals( + [['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']], + array_column($queries, 'bindings'), + ); + } + public function testOrWhereNotAllValues(): void { $this->getConnection()->unprepared('CREATE TABLE example (val text)'); @@ -267,6 +285,24 @@ public function testWhereLike(): void ); } + public function testWhereNotLike(): void + { + $this->getConnection()->unprepared('CREATE TABLE example (str text)'); + + $queries = $this->withQueryLog(function (): void { + $this->getConnection()->table('example')->whereNotLike('str', 'UkAymQlg')->get(); + $this->getConnection()->table('example')->whereNotLike('str', 'IcuC5Cqz', true)->get(); + }); + $this->assertEquals( + ['select * from "example" where "str" not ilike ?', 'select * from "example" where "str" not like ?'], + array_column($queries, 'query'), + ); + $this->assertEquals( + [['UkAymQlg'], ['IcuC5Cqz']], + array_column($queries, 'bindings'), + ); + } + public function testWhereNotAllValues(): void { $this->getConnection()->unprepared('CREATE TABLE example (val text)'); From 4e64ea31676f3e92db94dd3a65d93db974c5a273 Mon Sep 17 00:00:00 2001 From: mmachatschek Date: Mon, 3 Mar 2025 11:24:10 +0100 Subject: [PATCH 2/7] chore: use laravels implementation when we are on laravel >= 11.17.0 --- src/Query/BuilderWhere.php | 9 +++ src/Query/GrammarWhere.php | 7 ++- tests/Query/WhereTest.php | 117 ++++++++++++++++++++++++------------- 3 files changed, 92 insertions(+), 41 deletions(-) diff --git a/src/Query/BuilderWhere.php b/src/Query/BuilderWhere.php index 5fd3684..07d423f 100644 --- a/src/Query/BuilderWhere.php +++ b/src/Query/BuilderWhere.php @@ -5,6 +5,7 @@ namespace Tpetry\PostgresqlEnhanced\Query; use Illuminate\Database\Query\Expression; +use Illuminate\Support\Facades\App; trait BuilderWhere { @@ -67,6 +68,10 @@ public function orWhereIntegerArrayMatches($column, string $query): static */ public function orWhereLike($column, $value, $caseSensitive = false): static { + if (version_compare(App::version(), '11.17.0', '>=')) { + return parent::orWhereLike($column, $value, $caseSensitive); + } + return $this->whereLike($column, $value, $caseSensitive, 'or', false); } @@ -188,6 +193,10 @@ public function whereIntegerArrayMatches($column, string $query): static */ public function whereLike($column, $value, $caseSensitive = false, $boolean = 'and', $not = false): static { + if (version_compare(App::version(), '11.17.0', '>=')) { + return parent::whereLike($column, $value, $caseSensitive, $boolean, $not); + } + $type = 'like'; $this->wheres[] = compact('type', 'column', 'value', 'caseSensitive', 'boolean', 'not'); diff --git a/src/Query/GrammarWhere.php b/src/Query/GrammarWhere.php index 3dc98d0..6227491 100644 --- a/src/Query/GrammarWhere.php +++ b/src/Query/GrammarWhere.php @@ -6,6 +6,7 @@ use Exception; use Illuminate\Database\Query\Builder; +use Illuminate\Support\Facades\App; trait GrammarWhere { @@ -50,9 +51,13 @@ public function whereAny(Builder $query, $where): string */ public function whereLike(Builder $query, $where): string { + if (version_compare(App::version(), '11.17.0', '>=')) { + return parent::whereLike($query, $where); + } + $operator = $where['not'] ? 'not ' : ''; $operator .= $where['caseSensitive'] ? 'like' : 'ilike'; - + return "{$this->wrap($where['column'])} {$operator} {$this->parameter($where['value'])}"; } diff --git a/tests/Query/WhereTest.php b/tests/Query/WhereTest.php index a3a5549..2b50e66 100644 --- a/tests/Query/WhereTest.php +++ b/tests/Query/WhereTest.php @@ -4,6 +4,7 @@ namespace Tpetry\PostgresqlEnhanced\Tests\Query; +use Illuminate\Support\Facades\App; use Tpetry\PostgresqlEnhanced\Tests\TestCase; class WhereTest extends TestCase @@ -98,28 +99,19 @@ public function testOrWhereLike(): void $this->getConnection()->table('example')->orWhereLike('str', 'ZsbBUJmR')->orWhereLike('str', '7Cc1Uf8t')->get(); $this->getConnection()->table('example')->orWhereLike('str', 'OamekKIC', true)->orWhereLike('str', 'HmC3xURl', true)->get(); }); - $this->assertEquals( - ['select * from "example" where "str" ilike ? or "str" ilike ?', 'select * from "example" where "str" like ? or "str" like ?'], - array_column($queries, 'query'), - ); - $this->assertEquals( - [['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']], - array_column($queries, 'bindings'), - ); - } - public function testOrWhereNotLike(): void - { - $this->getConnection()->unprepared('CREATE TABLE example (str text)'); + if (version_compare(App::version(), '11.17.0', '>=')) { + $this->assertEquals( + ['select * from "example" where "str"::text ilike ? or "str"::text ilike ?', 'select * from "example" where "str"::text like ? or "str"::text like ?'], + array_column($queries, 'query'), + ); + } else { + $this->assertEquals( + ['select * from "example" where "str" ilike ? or "str" ilike ?', 'select * from "example" where "str" like ? or "str" like ?'], + array_column($queries, 'query'), + ); + } - $queries = $this->withQueryLog(function (): void { - $this->getConnection()->table('example')->orWhereNotLike('str', 'ZsbBUJmR')->orWhereNotLike('str', '7Cc1Uf8t')->get(); - $this->getConnection()->table('example')->orWhereNotLike('str', 'OamekKIC', true)->orWhereNotLike('str', 'HmC3xURl', true)->get(); - }); - $this->assertEquals( - ['select * from "example" where "str" not ilike ? or "str" not ilike ?', 'select * from "example" where "str" not like ? or "str" not like ?'], - array_column($queries, 'query'), - ); $this->assertEquals( [['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']], array_column($queries, 'bindings'), @@ -190,6 +182,33 @@ public function testOrWhereNotBoolean(): void ); } + public function testOrWhereNotLike(): void + { + $this->getConnection()->unprepared('CREATE TABLE example (str text)'); + + $queries = $this->withQueryLog(function (): void { + $this->getConnection()->table('example')->orWhereNotLike('str', 'ZsbBUJmR')->orWhereNotLike('str', '7Cc1Uf8t')->get(); + $this->getConnection()->table('example')->orWhereNotLike('str', 'OamekKIC', true)->orWhereNotLike('str', 'HmC3xURl', true)->get(); + }); + + if (version_compare(App::version(), '11.17.0', '>=')) { + $this->assertEquals( + ['select * from "example" where "str"::text not ilike ? or "str"::text not ilike ?', 'select * from "example" where "str"::text not like ? or "str"::text not like ?'], + array_column($queries, 'query'), + ); + } else { + $this->assertEquals( + ['select * from "example" where "str" not ilike ? or "str" not ilike ?', 'select * from "example" where "str" not like ? or "str" not like ?'], + array_column($queries, 'query'), + ); + } + + $this->assertEquals( + [['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']], + array_column($queries, 'bindings'), + ); + } + public function testWhereAllValues(): void { $this->getConnection()->unprepared('CREATE TABLE example (val text)'); @@ -275,28 +294,19 @@ public function testWhereLike(): void $this->getConnection()->table('example')->whereLike('str', 'UkAymQlg')->get(); $this->getConnection()->table('example')->whereLike('str', 'IcuC5Cqz', true)->get(); }); - $this->assertEquals( - ['select * from "example" where "str" ilike ?', 'select * from "example" where "str" like ?'], - array_column($queries, 'query'), - ); - $this->assertEquals( - [['UkAymQlg'], ['IcuC5Cqz']], - array_column($queries, 'bindings'), - ); - } - public function testWhereNotLike(): void - { - $this->getConnection()->unprepared('CREATE TABLE example (str text)'); + if (version_compare(App::version(), '11.17.0', '>=')) { + $this->assertEquals( + ['select * from "example" where "str"::text ilike ?', 'select * from "example" where "str"::text like ?'], + array_column($queries, 'query'), + ); + } else { + $this->assertEquals( + ['select * from "example" where "str" ilike ?', 'select * from "example" where "str" like ?'], + array_column($queries, 'query'), + ); + } - $queries = $this->withQueryLog(function (): void { - $this->getConnection()->table('example')->whereNotLike('str', 'UkAymQlg')->get(); - $this->getConnection()->table('example')->whereNotLike('str', 'IcuC5Cqz', true)->get(); - }); - $this->assertEquals( - ['select * from "example" where "str" not ilike ?', 'select * from "example" where "str" not like ?'], - array_column($queries, 'query'), - ); $this->assertEquals( [['UkAymQlg'], ['IcuC5Cqz']], array_column($queries, 'bindings'), @@ -366,4 +376,31 @@ public function testWhereNotBoolean(): void array_column($queries, 'query'), ); } + + public function testWhereNotLike(): void + { + $this->getConnection()->unprepared('CREATE TABLE example (str text)'); + + $queries = $this->withQueryLog(function (): void { + $this->getConnection()->table('example')->whereNotLike('str', 'UkAymQlg')->get(); + $this->getConnection()->table('example')->whereNotLike('str', 'IcuC5Cqz', true)->get(); + }); + + if (version_compare(App::version(), '11.17.0', '>=')) { + $this->assertEquals( + ['select * from "example" where "str"::text not ilike ?', 'select * from "example" where "str"::text not like ?'], + array_column($queries, 'query'), + ); + } else { + $this->assertEquals( + ['select * from "example" where "str" not ilike ?', 'select * from "example" where "str" not like ?'], + array_column($queries, 'query'), + ); + } + + $this->assertEquals( + [['UkAymQlg'], ['IcuC5Cqz']], + array_column($queries, 'bindings'), + ); + } } From ff9b257b1fc5c631e611fd9169a1b1716bbcba1d Mon Sep 17 00:00:00 2001 From: mmachatschek Date: Mon, 3 Mar 2025 16:00:57 +0100 Subject: [PATCH 3/7] chore: align queries with laravel 11.17+ behaviour --- src/Query/GrammarWhere.php | 7 +++- tests/Query/WhereTest.php | 69 +++++++++----------------------------- 2 files changed, 22 insertions(+), 54 deletions(-) diff --git a/src/Query/GrammarWhere.php b/src/Query/GrammarWhere.php index 6227491..6466ea1 100644 --- a/src/Query/GrammarWhere.php +++ b/src/Query/GrammarWhere.php @@ -58,7 +58,12 @@ public function whereLike(Builder $query, $where): string $operator = $where['not'] ? 'not ' : ''; $operator .= $where['caseSensitive'] ? 'like' : 'ilike'; - return "{$this->wrap($where['column'])} {$operator} {$this->parameter($where['value'])}"; + return sprintf( + '%s::text %s %s', + $this->wrap($where['column']), + $operator, + $this->parameter($where['value']), + ); } /** diff --git a/tests/Query/WhereTest.php b/tests/Query/WhereTest.php index 2b50e66..4cd642c 100644 --- a/tests/Query/WhereTest.php +++ b/tests/Query/WhereTest.php @@ -4,7 +4,6 @@ namespace Tpetry\PostgresqlEnhanced\Tests\Query; -use Illuminate\Support\Facades\App; use Tpetry\PostgresqlEnhanced\Tests\TestCase; class WhereTest extends TestCase @@ -99,19 +98,10 @@ public function testOrWhereLike(): void $this->getConnection()->table('example')->orWhereLike('str', 'ZsbBUJmR')->orWhereLike('str', '7Cc1Uf8t')->get(); $this->getConnection()->table('example')->orWhereLike('str', 'OamekKIC', true)->orWhereLike('str', 'HmC3xURl', true)->get(); }); - - if (version_compare(App::version(), '11.17.0', '>=')) { - $this->assertEquals( - ['select * from "example" where "str"::text ilike ? or "str"::text ilike ?', 'select * from "example" where "str"::text like ? or "str"::text like ?'], - array_column($queries, 'query'), - ); - } else { - $this->assertEquals( - ['select * from "example" where "str" ilike ? or "str" ilike ?', 'select * from "example" where "str" like ? or "str" like ?'], - array_column($queries, 'query'), - ); - } - + $this->assertEquals( + ['select * from "example" where "str"::text ilike ? or "str"::text ilike ?', 'select * from "example" where "str"::text like ? or "str"::text like ?'], + array_column($queries, 'query'), + ); $this->assertEquals( [['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']], array_column($queries, 'bindings'), @@ -190,19 +180,10 @@ public function testOrWhereNotLike(): void $this->getConnection()->table('example')->orWhereNotLike('str', 'ZsbBUJmR')->orWhereNotLike('str', '7Cc1Uf8t')->get(); $this->getConnection()->table('example')->orWhereNotLike('str', 'OamekKIC', true)->orWhereNotLike('str', 'HmC3xURl', true)->get(); }); - - if (version_compare(App::version(), '11.17.0', '>=')) { - $this->assertEquals( - ['select * from "example" where "str"::text not ilike ? or "str"::text not ilike ?', 'select * from "example" where "str"::text not like ? or "str"::text not like ?'], - array_column($queries, 'query'), - ); - } else { - $this->assertEquals( - ['select * from "example" where "str" not ilike ? or "str" not ilike ?', 'select * from "example" where "str" not like ? or "str" not like ?'], - array_column($queries, 'query'), - ); - } - + $this->assertEquals( + ['select * from "example" where "str"::text not ilike ? or "str"::text not ilike ?', 'select * from "example" where "str"::text not like ? or "str"::text not like ?'], + array_column($queries, 'query'), + ); $this->assertEquals( [['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']], array_column($queries, 'bindings'), @@ -294,19 +275,10 @@ public function testWhereLike(): void $this->getConnection()->table('example')->whereLike('str', 'UkAymQlg')->get(); $this->getConnection()->table('example')->whereLike('str', 'IcuC5Cqz', true)->get(); }); - - if (version_compare(App::version(), '11.17.0', '>=')) { - $this->assertEquals( - ['select * from "example" where "str"::text ilike ?', 'select * from "example" where "str"::text like ?'], - array_column($queries, 'query'), - ); - } else { - $this->assertEquals( - ['select * from "example" where "str" ilike ?', 'select * from "example" where "str" like ?'], - array_column($queries, 'query'), - ); - } - + $this->assertEquals( + ['select * from "example" where "str"::text ilike ?', 'select * from "example" where "str"::text like ?'], + array_column($queries, 'query'), + ); $this->assertEquals( [['UkAymQlg'], ['IcuC5Cqz']], array_column($queries, 'bindings'), @@ -385,19 +357,10 @@ public function testWhereNotLike(): void $this->getConnection()->table('example')->whereNotLike('str', 'UkAymQlg')->get(); $this->getConnection()->table('example')->whereNotLike('str', 'IcuC5Cqz', true)->get(); }); - - if (version_compare(App::version(), '11.17.0', '>=')) { - $this->assertEquals( - ['select * from "example" where "str"::text not ilike ?', 'select * from "example" where "str"::text not like ?'], - array_column($queries, 'query'), - ); - } else { - $this->assertEquals( - ['select * from "example" where "str" not ilike ?', 'select * from "example" where "str" not like ?'], - array_column($queries, 'query'), - ); - } - + $this->assertEquals( + ['select * from "example" where "str"::text not ilike ?', 'select * from "example" where "str"::text not like ?'], + array_column($queries, 'query'), + ); $this->assertEquals( [['UkAymQlg'], ['IcuC5Cqz']], array_column($queries, 'bindings'), From a2928a532bedf975764ce4b9a56b05cb6c336bcf Mon Sep 17 00:00:00 2001 From: Markus Machatschek Date: Mon, 3 Mar 2025 16:04:43 +0100 Subject: [PATCH 4/7] chore: remove version check in the like implementations as well --- src/Query/BuilderWhere.php | 9 --------- src/Query/GrammarWhere.php | 5 ----- 2 files changed, 14 deletions(-) diff --git a/src/Query/BuilderWhere.php b/src/Query/BuilderWhere.php index 07d423f..5fd3684 100644 --- a/src/Query/BuilderWhere.php +++ b/src/Query/BuilderWhere.php @@ -5,7 +5,6 @@ namespace Tpetry\PostgresqlEnhanced\Query; use Illuminate\Database\Query\Expression; -use Illuminate\Support\Facades\App; trait BuilderWhere { @@ -68,10 +67,6 @@ public function orWhereIntegerArrayMatches($column, string $query): static */ public function orWhereLike($column, $value, $caseSensitive = false): static { - if (version_compare(App::version(), '11.17.0', '>=')) { - return parent::orWhereLike($column, $value, $caseSensitive); - } - return $this->whereLike($column, $value, $caseSensitive, 'or', false); } @@ -193,10 +188,6 @@ public function whereIntegerArrayMatches($column, string $query): static */ public function whereLike($column, $value, $caseSensitive = false, $boolean = 'and', $not = false): static { - if (version_compare(App::version(), '11.17.0', '>=')) { - return parent::whereLike($column, $value, $caseSensitive, $boolean, $not); - } - $type = 'like'; $this->wheres[] = compact('type', 'column', 'value', 'caseSensitive', 'boolean', 'not'); diff --git a/src/Query/GrammarWhere.php b/src/Query/GrammarWhere.php index 6466ea1..7c1b7c4 100644 --- a/src/Query/GrammarWhere.php +++ b/src/Query/GrammarWhere.php @@ -6,7 +6,6 @@ use Exception; use Illuminate\Database\Query\Builder; -use Illuminate\Support\Facades\App; trait GrammarWhere { @@ -51,10 +50,6 @@ public function whereAny(Builder $query, $where): string */ public function whereLike(Builder $query, $where): string { - if (version_compare(App::version(), '11.17.0', '>=')) { - return parent::whereLike($query, $where); - } - $operator = $where['not'] ? 'not ' : ''; $operator .= $where['caseSensitive'] ? 'like' : 'ilike'; From 097b857a99ffa4460aea99bfffbdea5f92df5b87 Mon Sep 17 00:00:00 2001 From: tpetry Date: Mon, 3 Mar 2025 16:21:07 +0100 Subject: [PATCH 5/7] code style --- src/Query/GrammarWhere.php | 7 +------ tests/Query/WhereTest.php | 12 ++++++------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/Query/GrammarWhere.php b/src/Query/GrammarWhere.php index 7c1b7c4..b321a97 100644 --- a/src/Query/GrammarWhere.php +++ b/src/Query/GrammarWhere.php @@ -53,12 +53,7 @@ public function whereLike(Builder $query, $where): string $operator = $where['not'] ? 'not ' : ''; $operator .= $where['caseSensitive'] ? 'like' : 'ilike'; - return sprintf( - '%s::text %s %s', - $this->wrap($where['column']), - $operator, - $this->parameter($where['value']), - ); + return "{$this->wrap($where['column'])}::text {$operator} {$this->parameter($where['value'])}"; } /** diff --git a/tests/Query/WhereTest.php b/tests/Query/WhereTest.php index 4cd642c..79a1e53 100644 --- a/tests/Query/WhereTest.php +++ b/tests/Query/WhereTest.php @@ -177,15 +177,15 @@ public function testOrWhereNotLike(): void $this->getConnection()->unprepared('CREATE TABLE example (str text)'); $queries = $this->withQueryLog(function (): void { - $this->getConnection()->table('example')->orWhereNotLike('str', 'ZsbBUJmR')->orWhereNotLike('str', '7Cc1Uf8t')->get(); - $this->getConnection()->table('example')->orWhereNotLike('str', 'OamekKIC', true)->orWhereNotLike('str', 'HmC3xURl', true)->get(); + $this->getConnection()->table('example')->orWhereNotLike('str', 'AERLFW4s')->orWhereNotLike('str', 'sPtXxruW')->get(); + $this->getConnection()->table('example')->orWhereNotLike('str', 'EWnGRRc5', true)->orWhereNotLike('str', 'wihuWcph', true)->get(); }); $this->assertEquals( ['select * from "example" where "str"::text not ilike ? or "str"::text not ilike ?', 'select * from "example" where "str"::text not like ? or "str"::text not like ?'], array_column($queries, 'query'), ); $this->assertEquals( - [['ZsbBUJmR', '7Cc1Uf8t'], ['OamekKIC', 'HmC3xURl']], + [['AERLFW4s', 'sPtXxruW'], ['EWnGRRc5', 'wihuWcph']], array_column($queries, 'bindings'), ); } @@ -354,15 +354,15 @@ public function testWhereNotLike(): void $this->getConnection()->unprepared('CREATE TABLE example (str text)'); $queries = $this->withQueryLog(function (): void { - $this->getConnection()->table('example')->whereNotLike('str', 'UkAymQlg')->get(); - $this->getConnection()->table('example')->whereNotLike('str', 'IcuC5Cqz', true)->get(); + $this->getConnection()->table('example')->whereNotLike('str', 'mgb7DtKz')->get(); + $this->getConnection()->table('example')->whereNotLike('str', 'tpx6Bxpm', true)->get(); }); $this->assertEquals( ['select * from "example" where "str"::text not ilike ?', 'select * from "example" where "str"::text not like ?'], array_column($queries, 'query'), ); $this->assertEquals( - [['UkAymQlg'], ['IcuC5Cqz']], + [['mgb7DtKz'], ['tpx6Bxpm']], array_column($queries, 'bindings'), ); } From 45b7aa8590686cbf327641b1d2fbd3062891ad0d Mon Sep 17 00:00:00 2001 From: tpetry Date: Mon, 3 Mar 2025 16:23:58 +0100 Subject: [PATCH 6/7] phpstan --- src/Query/GrammarWhere.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Query/GrammarWhere.php b/src/Query/GrammarWhere.php index b321a97..0f5acc7 100644 --- a/src/Query/GrammarWhere.php +++ b/src/Query/GrammarWhere.php @@ -46,7 +46,7 @@ public function whereAny(Builder $query, $where): string /** * Compile a "like" clause. * - * @param array{caseSensitive: bool, column: string, value: mixed} $where + * @param array{caseSensitive: bool, column: string, not: bool, value: mixed} $where */ public function whereLike(Builder $query, $where): string { From 274a79b0e9ce33d0c132eb245cfff4f27c757f98 Mon Sep 17 00:00:00 2001 From: tpetry Date: Mon, 3 Mar 2025 16:30:00 +0100 Subject: [PATCH 7/7] support for old Laravel versions --- src/Query/BuilderWhere.php | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Query/BuilderWhere.php b/src/Query/BuilderWhere.php index 5fd3684..5aac70a 100644 --- a/src/Query/BuilderWhere.php +++ b/src/Query/BuilderWhere.php @@ -110,6 +110,18 @@ public function orWhereNotBoolean($column, bool $value): static return $this->orWhere($column, '!=', new Expression(var_export($value, true))); } + /** + * Add an "or where not like" clause to the query. + * + * @param Expression|string $column + * @param Expression|string $value + * @param bool $caseSensitive + */ + public function orWhereNotLike($column, $value, $caseSensitive = false): static + { + return $this->whereNotLike($column, $value, $caseSensitive, 'or'); + } + /** * Add a where all statement to the query. * @@ -178,7 +190,7 @@ public function whereIntegerArrayMatches($column, string $query): static } /** - * Add a "where month" statement to the query. + * Add a "where like" statement to the query. * * @param Expression|string $column * @param Expression|string $value @@ -235,4 +247,17 @@ public function whereNotBoolean($column, bool $value): static { return $this->where($column, '!=', new Expression(var_export($value, true))); } + + /** + * Add a "where not like" statement to the query. + * + * @param Expression|string $column + * @param Expression|string $value + * @param bool $caseSensitive + * @param string $boolean + */ + public function whereNotLike($column, $value, $caseSensitive = false, $boolean = 'and'): static + { + return $this->whereLike($column, $value, $caseSensitive, $boolean, true); + } }