Skip to content

Commit 069c0b5

Browse files
committed
fix search scope to support json columns
1 parent b155102 commit 069c0b5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/Expansions/Builder.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ function ($query) use ($column, $search, $strict) {
4141
}
4242
} else {
4343
foreach ($column as $c) {
44+
if (Str::contains($c, '->')) {
45+
$jsonQueryPath = explode('->', $c);
46+
if (count($jsonQueryPath) !== 2) continue;
47+
48+
[$column, $property] = $jsonQueryPath;
49+
$query->orWhere(DB::raw("lower(json_unquote(json_extract($column, '$.$property')))"), 'LIKE', '%' . str_replace('.', '%', str_replace(',', '%', $search)) . '%');
50+
continue;
51+
}
4452
$query->orWhere(DB::raw("lower($c)"), 'like', '%' . str_replace('.', '%', str_replace(',', '%', $search)) . '%');
4553
}
4654
}
@@ -52,6 +60,14 @@ function ($query) use ($column, $search, $strict) {
5260
return $this->where($column, $search);
5361
}
5462

63+
if (Str::contains($column, '->')) {
64+
$jsonQueryPath = explode('->', $column);
65+
if (count($jsonQueryPath) !== 2) return;
66+
67+
[$column, $property] = $jsonQueryPath;
68+
return $this->where(DB::raw("lower(json_unquote(json_extract($column, '$.$property')))"), 'LIKE', '%' . str_replace('.', '%', str_replace(',', '%', $search)) . '%');
69+
}
70+
5571
return $this->where(DB::raw("lower($column)"), 'like', '%' . str_replace('.', '%', str_replace(',', '%', $search)) . '%');
5672
};
5773
}

0 commit comments

Comments
 (0)