Skip to content

Commit 5f1c063

Browse files
innocenzitpetry
andauthored
fix: fix: compatability to Laravel 11.17 (resolves #89)
Co-authored-by: tpetry <[email protected]>
1 parent 9a06d13 commit 5f1c063

File tree

5 files changed

+17
-14
lines changed

5 files changed

+17
-14
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,11 +1103,11 @@ $query->orWhereNotBoolean($column, bool $value);
11031103

11041104
#### Like
11051105

1106-
With the `whereLike` scope you can compare a column to a (case-insensitive) value.
1106+
With the `whereLike` scope you can do case-(in)sensitive like comparisons between a column and a value.
11071107

11081108
```php
1109-
$query->whereLike($column, $value, $caseInsensitive = false);
1110-
$query->orWhereLike($column, $value, $caseInsensitive = false);
1109+
$query->whereLike($column, $value, $caseSensitive = false);
1110+
$query->orWhereLike($column, $value, $caseSensitive = false);
11111111
```
11121112

11131113
#### Between Symmetric

src/Query/BuilderWhere.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ public function orWhereIntegerArrayMatches($column, string $query): static
6363
*
6464
* @param Expression|string $column
6565
* @param Expression|string $value
66+
* @param bool $caseSensitive
6667
*/
67-
public function orWhereLike($column, $value, bool $caseInsensitive = false): static
68+
public function orWhereLike($column, $value, $caseSensitive = false): static
6869
{
69-
return $this->whereLike($column, $value, $caseInsensitive, 'or');
70+
return $this->whereLike($column, $value, $caseSensitive, 'or', false);
7071
}
7172

7273
/**
@@ -181,13 +182,15 @@ public function whereIntegerArrayMatches($column, string $query): static
181182
*
182183
* @param Expression|string $column
183184
* @param Expression|string $value
185+
* @param bool $caseSensitive
184186
* @param string $boolean
187+
* @param bool $not
185188
*/
186-
public function whereLike($column, $value, bool $caseInsensitive = false, $boolean = 'and'): static
189+
public function whereLike($column, $value, $caseSensitive = false, $boolean = 'and', $not = false): static
187190
{
188191
$type = 'like';
189192

190-
$this->wheres[] = compact('type', 'column', 'value', 'caseInsensitive', 'boolean');
193+
$this->wheres[] = compact('type', 'column', 'value', 'caseSensitive', 'boolean', 'not');
191194
$this->addBinding($value);
192195

193196
return $this;

src/Query/GrammarWhere.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ public function whereAny(Builder $query, $where): string
4646
/**
4747
* Compile a "like" clause.
4848
*
49-
* @param array{caseInsensitive: bool, column: string, value: mixed} $where
49+
* @param array{caseSensitive: bool, column: string, value: mixed} $where
5050
*/
5151
public function whereLike(Builder $query, $where): string
5252
{
53-
return match ((bool) $where['caseInsensitive']) {
54-
true => "{$this->wrap($where['column'])} ilike {$this->parameter($where['value'])}",
55-
false => "{$this->wrap($where['column'])} like {$this->parameter($where['value'])}",
53+
return match ($where['caseSensitive']) {
54+
true => "{$this->wrap($where['column'])} like {$this->parameter($where['value'])}",
55+
false => "{$this->wrap($where['column'])} ilike {$this->parameter($where['value'])}",
5656
};
5757
}
5858

src/Schema/Grammars/GrammarTable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Tpetry\PostgresqlEnhanced\Schema\Grammars;
66

7+
use Arr;
78
use Illuminate\Database\Schema\Blueprint;
8-
use Illuminate\Support\Arr;
99
use Illuminate\Support\Fluent;
1010

1111
trait GrammarTable

tests/Query/WhereTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public function testOrWhereLike(): void
9999
$this->getConnection()->table('example')->orWhereLike('str', 'OamekKIC', true)->orWhereLike('str', 'HmC3xURl', true)->get();
100100
});
101101
$this->assertEquals(
102-
['select * from "example" where "str" like ? or "str" like ?', 'select * from "example" where "str" ilike ? or "str" ilike ?'],
102+
['select * from "example" where "str" ilike ? or "str" ilike ?', 'select * from "example" where "str" like ? or "str" like ?'],
103103
array_column($queries, 'query'),
104104
);
105105
$this->assertEquals(
@@ -258,7 +258,7 @@ public function testWhereLike(): void
258258
$this->getConnection()->table('example')->whereLike('str', 'IcuC5Cqz', true)->get();
259259
});
260260
$this->assertEquals(
261-
['select * from "example" where "str" like ?', 'select * from "example" where "str" ilike ?'],
261+
['select * from "example" where "str" ilike ?', 'select * from "example" where "str" like ?'],
262262
array_column($queries, 'query'),
263263
);
264264
$this->assertEquals(

0 commit comments

Comments
 (0)