Skip to content

Commit

Permalink
'fix-bug'
Browse files Browse the repository at this point in the history
  • Loading branch information
huangbule committed Mar 27, 2024
1 parent fc67595 commit 621fa7c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 16 deletions.
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"email": "[email protected]"
}
],
"require": {},
"require": {
"php": "^7.4|^8.0"
},
"autoload": {
"psr-4": {
"Huangbule\\LaravelEloquentFilter\\": "src"
Expand Down
20 changes: 5 additions & 15 deletions src/Traits/FilterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@ public function scopeFilter($query, $param = [], $arr_filter = [])
}
$operator ??= config('filter.default');
$arr_operator = explode("|", $operator);
//判断是否有@开头,表示是别名
foreach ($arr_operator as $k => $command) {
if (Str::contains($command, '@')) {
$this->renamedFilterFields[$search_key] = substr($command, 1);
unset($arr_operator[$k]);
break;
}
}

$relation = null;
$filter_command = config('filter.default');
Expand All @@ -78,13 +70,6 @@ public function scopeFilter($query, $param = [], $arr_filter = [])
if (!$command)
throw new InvalidArgumentException($arr_filter[$key] . " format not valid");

//check rename or not
if (isset($this->renamedFilterFields[$search_key]) && !empty($param[$search_key])) {
$old_search_key = $search_key;
$search_key = $this->renamedFilterFields[$search_key];
$param[$search_key] = $param[$old_search_key];
}

if (Str::startsWith($command, '$')) {
$filter_command = $command;
} elseif (Str::startsWith($command, '#')) {
Expand All @@ -93,6 +78,11 @@ public function scopeFilter($query, $param = [], $arr_filter = [])
if (!method_exists(static::class, $relation)) {
throw new NotFoundException("'" . get_class(new static()) . "' has not found relation : " . $relation);
}
} elseif (Str::startsWith($command, '@')) { //判断是否有@开头,表示是别名
$old_search_key = $search_key;
$search_key = substr($command, 1);
$param[$search_key] = $param[$old_search_key];
continue;
} else {
$process_class = Str::beforeLast(__NAMESPACE__, "Traits") . "Preprocess\\" . Str::studly($command . "Preprocess");
if (class_exists($process_class)) {
Expand Down

0 comments on commit 621fa7c

Please sign in to comment.