Skip to content

Commit a98cbae

Browse files
committed
fix: 简化 search 参数
1 parent 49cd2dd commit a98cbae

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/SearchTrait.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function scopeSearch($query, $params)
6060
if (is_array($params)) {
6161
foreach ($params as $key => $_param) {
6262
$param = [];
63-
if (is_array($_param)) {
63+
if (is_array($_param) && array_has($_param, 'column') && array_has($_param, 'value')) {
6464
$param['column'] = array_get($_param, 'column', $key);
6565
$param['operator'] = array_get($_param, 'operator', '=');
6666
$param['value'] = array_get($_param, 'value', null);
@@ -69,8 +69,16 @@ public function scopeSearch($query, $params)
6969
if ($_param == null) {
7070
continue;
7171
}
72-
$param['column'] = $key;
73-
$param['operator'] = '=';
72+
73+
if (stripos(':', $key) !== false) {
74+
$arr = explode(':', $key);
75+
$param['column'] = $arr[0];
76+
$param['operator'] = isset($arr[1]) ? $arr[0] : '=';
77+
} else {
78+
$param['column'] = $key;
79+
$param['operator'] = '=';
80+
}
81+
7482
$param['value'] = $_param;
7583
}
7684

0 commit comments

Comments
 (0)