Skip to content

Commit

Permalink
Merge pull request #58 from mehdi-fathi/mehdi-dev
Browse files Browse the repository at this point in the history
Fix:fix some bugs
  • Loading branch information
mehdi-fathi authored Feb 26, 2020
2 parents 051ec05 + 0ea49bb commit 6e55c52
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/QueryFilter/Queries/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function buildQuery($field, array $params)
$this->queryFilterBuilder->whereByOpt($field, $params);
} elseif (is_array($params[0])) {
$this->queryFilterBuilder->whereIn("$field", $params[0]);
} else {
} elseif (!empty($params[0])) {
$this->queryFilterBuilder->where("$field", $params[0]);
}
}
Expand Down
9 changes: 8 additions & 1 deletion src/QueryFilter/Queries/QueryFilterBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,14 @@ public function whereByOpt($field, $params)
*/
public function whereIn($field, array $params)
{
$this->builder->whereIn("$field", $params);
foreach ($params as $key => $value) {
if (is_null($value) || $value == '') {
unset($params[$key]);
}
}
if (!empty($params)) {
$this->builder->whereIn("$field", $params);
}
}

/**
Expand Down
2 changes: 0 additions & 2 deletions tests/Tests/CategoryFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public function itCanGetCategoryByCategoryAndDateNull()
$request->merge(
[
'category' => 'Html',
'created_at' => null,
]
);
$modelfilter = new ModelFilters(
Expand All @@ -35,7 +34,6 @@ public function itCanGetCategoryByCategoryAndDateNull()
$category = CategoriesController::filterCategory($modelfilter);
$category_pure = Category::where([
'category' => 'Html',
'created_at' => null,
])->get();

$this->assertEquals($category, $category_pure);
Expand Down

0 comments on commit 6e55c52

Please sign in to comment.