Unverified Commit 2d76d22a authored by Jens Segers's avatar Jens Segers Committed by GitHub

Merge pull request #1829 from ahmedsayedabdelsalam/master

fix filtering with operator not like issue
parents f3f230a9 30098cd3
......@@ -978,9 +978,13 @@ class Builder extends BaseBuilder
{
extract($where);
// Replace like with a Regex instance.
if ($operator == 'like') {
$operator = '=';
// Replace like or not like with a Regex instance.
if (in_array($operator, ['like', 'not like'])) {
if ($operator === 'not like') {
$operator = 'not';
} else {
$operator = '=';
}
// Convert to regular expression.
$regex = preg_replace('#(^|[^\\\])%#', '$1.*', preg_quote($value));
......
......@@ -71,6 +71,21 @@ class QueryTest extends TestCase
$this->assertCount(1, $users);
}
public function testNotLike(): void
{
$users = User::where('name', 'not like', '%doe')->get();
$this->assertCount(7, $users);
$users = User::where('name', 'not like', '%y%')->get();
$this->assertCount(6, $users);
$users = User::where('name', 'not LIKE', '%y%')->get();
$this->assertCount(6, $users);
$users = User::where('name', 'not like', 't%')->get();
$this->assertCount(8, $users);
}
public function testSelect(): void
{
$user = User::where('name', 'John Doe')->select('name')->first();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment