Skip to content

Commit b24ea76

Browse files
committed
fix: 简化 search 参数
1 parent 11bc869 commit b24ea76

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/SearchTrait.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,20 @@ public function scopeWhereEndsWith($query, $column, $value, $boolean = 'and')
5858
public function scopeSearch($query, $params)
5959
{
6060
if (is_array($params)) {
61-
foreach ($params as $key => $param) {
62-
if (! array_has($param, ['column', 'operator', 'values'])) {
63-
continue;
61+
foreach ($params as $key => $_param) {
62+
$param = [];
63+
if (is_array($_param)) {
64+
$param['column'] = array_get($_param, 'column', $key);
65+
$param['operator'] = array_get($_param, 'operator', '=');
66+
$param['values'] = array_get($_param, 'values', null);
67+
68+
} else {
69+
if ($_param == null) {
70+
continue;
71+
}
72+
$param['column'] = $key;
73+
$param['operator'] = '=';
74+
$param['values'] = $_param;
6475
}
6576

6677
if ($param['values'] == null) {

0 commit comments

Comments
 (0)