- /**
- * Apply a tag search term onto a entity query.
- */
- protected function applyTagSearch(EloquentBuilder $query, string $tagTerm): EloquentBuilder
- {
- preg_match('/^(.*?)((' . $this->getRegexEscapedOperators() . ')(.*?))?$/', $tagTerm, $tagSplit);
- $query->whereHas('tags', function (EloquentBuilder $query) use ($tagSplit) {
- $tagName = $tagSplit[1];
- $tagOperator = count($tagSplit) > 2 ? $tagSplit[3] : '';
- $tagValue = count($tagSplit) > 3 ? $tagSplit[4] : '';
- $validOperator = in_array($tagOperator, $this->queryOperators);
- if (!empty($tagOperator) && !empty($tagValue) && $validOperator) {
- if (!empty($tagName)) {
- $query->where('name', '=', $tagName);
- }
- if (is_numeric($tagValue) && $tagOperator !== 'like') {
- // We have to do a raw sql query for this since otherwise PDO will quote the value and MySQL will
- // search the value as a string which prevents being able to do number-based operations
- // on the tag values. We ensure it has a numeric value and then cast it just to be sure.
- /** @var Connection $connection */
- $connection = $query->getConnection();
- $tagValue = (float) trim($connection->getPdo()->quote($tagValue), "'");
- $query->whereRaw("value {$tagOperator} {$tagValue}");
- } else {
- if ($tagOperator === 'like') {
- $tagValue = str_replace('\\', '\\\\', $tagValue);
- }
- $query->where('value', $tagOperator, $tagValue);
- }
+ if (is_numeric($tagParts['value']) && $tagParts['operator'] !== 'like') {
+ // We have to do a raw sql query for this since otherwise PDO will quote the value and MySQL will
+ // search the value as a string which prevents being able to do number-based operations
+ // on the tag values. We ensure it has a numeric value and then cast it just to be sure.
+ /** @var Connection $connection */
+ $connection = $query->getConnection();
+ $quotedValue = (float) trim($connection->getPdo()->quote($tagParts['value']), "'");
+ $query->whereRaw("value {$tagParts['operator']} {$quotedValue}");
+ } else if ($tagParts['operator'] === 'like') {
+ $query->where('value', $tagParts['operator'], str_replace('\\', '\\\\', $tagParts['value']));