Skip to content

Commit

Permalink
fix: fix: compatability to Laravel 11.17 (resolves #89)
Browse files Browse the repository at this point in the history
Co-authored-by: tpetry <[email protected]>
  • Loading branch information
innocenzi and tpetry authored Jul 31, 2024
1 parent 9a06d13 commit 5f1c063
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
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
2 changes: 1 addition & 1 deletion src/Schema/Grammars/GrammarTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Tpetry\PostgresqlEnhanced\Schema\Grammars;

use Arr;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Arr;
use Illuminate\Support\Fluent;

trait GrammarTable
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

0 comments on commit 5f1c063

Please sign in to comment.