Skip to content

Commit

Permalink
增加whereOrJsonContains方法
Browse files Browse the repository at this point in the history
  • Loading branch information
liu21st committed Sep 4, 2024
1 parent 2dbbe9e commit fd9ca44
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/db/concern/WhereQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,16 @@ public function whereJsonContains(string $field, $condition, string $logic = 'AN
[$field1, $field2] = explode('->', $field);
$field = 'json_extract(' . $field1 . ',\'$.' . $field2 . '\')';
}

$value = is_string($condition) ? '"' . $condition . '"' : $condition;
return $this->whereRaw('json_contains(' . $field . ',\'' . $value . '\')');

$value = is_string($condition) ? '"' . $condition . '"' : $condition;
$name = $this->bindValue($value);
$bind[$name] = $value;
return $this->whereRaw('json_contains(' . $field . ',:' . $name . ')', $bind, $logic);
}

public function whereOrJsonContains(string $field, $condition)
{
return $this->whereJsonContains($field, $condition, 'OR');
}

/**
Expand Down

0 comments on commit fd9ca44

Please sign in to comment.