Skip to content

Commit

Permalink
fix: 简化 search 参数
Browse files Browse the repository at this point in the history
  • Loading branch information
westhack committed Jul 23, 2019
1 parent 49cd2dd commit a98cbae
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/SearchTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function scopeSearch($query, $params)
if (is_array($params)) {
foreach ($params as $key => $_param) {
$param = [];
if (is_array($_param)) {
if (is_array($_param) && array_has($_param, 'column') && array_has($_param, 'value')) {
$param['column'] = array_get($_param, 'column', $key);
$param['operator'] = array_get($_param, 'operator', '=');
$param['value'] = array_get($_param, 'value', null);
Expand All @@ -69,8 +69,16 @@ public function scopeSearch($query, $params)
if ($_param == null) {
continue;
}
$param['column'] = $key;
$param['operator'] = '=';

if (stripos(':', $key) !== false) {
$arr = explode(':', $key);
$param['column'] = $arr[0];
$param['operator'] = isset($arr[1]) ? $arr[0] : '=';
} else {
$param['column'] = $key;
$param['operator'] = '=';
}

$param['value'] = $_param;
}

Expand Down

0 comments on commit a98cbae

Please sign in to comment.