Skip to content
This repository was archived by the owner on Jan 9, 2024. It is now read-only.

Commit 83e0662

Browse files
gmartinezmsonowal
authored andcommitted
Support json columns using '->' syntax in where()
1 parent fd9d3af commit 83e0662

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/Engines/Modes/Mode.php

+11
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,17 @@ private function parseWheres($wheres)
6464
$result [] = !empty($matches) ? array($matches[1], $matches[2], $value) : array($field, '=', $value);
6565
}
6666

67+
/**
68+
* Add support for where() on json columns using '->' syntax
69+
* data->a->b->c translates to json_unquote(json_extract(`data`, '$."a"."b"."c"'))
70+
*/
71+
foreach ($result as $_k => $_v) {
72+
if (($_v[0] ?? false) && stripos($_v[0],'->')!==false) {
73+
list($root,$path) = explode('->',$_v[0],2);
74+
$result[$_k][0] = "json_unquote(json_extract(`$root`, '$.\"".implode('"."',explode('->',$path))."\"'))";
75+
}
76+
}
77+
6778
return $result;
6879
}
6980
}

0 commit comments

Comments
 (0)