Skip to content

fix: compatability to Laravel 11.17 #90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1103,11 +1103,11 @@ $query->orWhereNotBoolean($column, bool $value);

#### Like

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

```php
$query->whereLike($column, $value, $caseInsensitive = false);
$query->orWhereLike($column, $value, $caseInsensitive = false);
$query->whereLike($column, $value, $caseSensitive = false);
$query->orWhereLike($column, $value, $caseSensitive = false);
```

#### Between Symmetric
Expand Down
11 changes: 7 additions & 4 deletions src/Query/BuilderWhere.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ public function orWhereIntegerArrayMatches($column, string $query): static
*
* @param Expression|string $column
* @param Expression|string $value
* @param bool $caseSensitive
*/
public function orWhereLike($column, $value, bool $caseInsensitive = false): static
public function orWhereLike($column, $value, $caseSensitive = false): static
{
return $this->whereLike($column, $value, $caseInsensitive, 'or');
return $this->whereLike($column, $value, $caseSensitive, 'or', false);
}

/**
Expand Down Expand Up @@ -181,13 +182,15 @@ public function whereIntegerArrayMatches($column, string $query): static
*
* @param Expression|string $column
* @param Expression|string $value
* @param bool $caseSensitive
* @param string $boolean
* @param bool $not
*/
public function whereLike($column, $value, bool $caseInsensitive = false, $boolean = 'and'): static
public function whereLike($column, $value, $caseSensitive = false, $boolean = 'and', $not = false): static
{
$type = 'like';

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

return $this;
Expand Down
8 changes: 4 additions & 4 deletions src/Query/GrammarWhere.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public function whereAny(Builder $query, $where): string
/**
* Compile a "like" clause.
*
* @param array{caseInsensitive: bool, column: string, value: mixed} $where
* @param array{caseSensitive: bool, column: string, value: mixed} $where
*/
public function whereLike(Builder $query, $where): string
{
return match ((bool) $where['caseInsensitive']) {
true => "{$this->wrap($where['column'])} ilike {$this->parameter($where['value'])}",
false => "{$this->wrap($where['column'])} like {$this->parameter($where['value'])}",
return match ($where['caseSensitive']) {
true => "{$this->wrap($where['column'])} like {$this->parameter($where['value'])}",
false => "{$this->wrap($where['column'])} ilike {$this->parameter($where['value'])}",
};
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Query/WhereTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function testOrWhereLike(): void
$this->getConnection()->table('example')->orWhereLike('str', 'OamekKIC', true)->orWhereLike('str', 'HmC3xURl', true)->get();
});
$this->assertEquals(
['select * from "example" where "str" like ? or "str" like ?', 'select * from "example" where "str" ilike ? or "str" ilike ?'],
['select * from "example" where "str" ilike ? or "str" ilike ?', 'select * from "example" where "str" like ? or "str" like ?'],
array_column($queries, 'query'),
);
$this->assertEquals(
Expand Down Expand Up @@ -258,7 +258,7 @@ public function testWhereLike(): void
$this->getConnection()->table('example')->whereLike('str', 'IcuC5Cqz', true)->get();
});
$this->assertEquals(
['select * from "example" where "str" like ?', 'select * from "example" where "str" ilike ?'],
['select * from "example" where "str" ilike ?', 'select * from "example" where "str" like ?'],
array_column($queries, 'query'),
);
$this->assertEquals(
Expand Down
Loading