diff --git a/src/NwLaravel/Repositories/Criterias/Filters/FilterClosure.php b/src/NwLaravel/Repositories/Criterias/Filters/FilterClosure.php index 252b774..d683320 100644 --- a/src/NwLaravel/Repositories/Criterias/Filters/FilterClosure.php +++ b/src/NwLaravel/Repositories/Criterias/Filters/FilterClosure.php @@ -14,8 +14,12 @@ class FilterClosure implements FilterInterface */ public function filter($query, $key, $value) { - if (is_int($key) && $value instanceof \Closure) { - $query = $query->where($value); + if ($value instanceof \Closure) { + if (is_int($key)) { + $query = $query->where($value); + } else { + $query = $query->whereIn($key, $value); + } return true; } diff --git a/src/NwLaravel/Repositories/Eloquent/AbstractRepository.php b/src/NwLaravel/Repositories/Eloquent/AbstractRepository.php index 4d528db..eb25dd2 100644 --- a/src/NwLaravel/Repositories/Eloquent/AbstractRepository.php +++ b/src/NwLaravel/Repositories/Eloquent/AbstractRepository.php @@ -65,7 +65,10 @@ public function getQuery() $this->applyCriteria(); $this->applyScope(); - return $this->model; + $model = $this->model; + + $this->resetModel(); + return $model; } /** @@ -89,7 +92,6 @@ public function searchAll(array $input, $orderBy = '', $limit = null, $skipPrese ->getQuery() ->limit($limit); - $this->resetModel(); return new BuilderResultset($query); } @@ -125,7 +127,6 @@ public function resultset($limit = null) { $query = $this->getQuery()->limit($limit); - $this->resetModel(); return new BuilderResultset($query); } @@ -139,13 +140,7 @@ public function resultset($limit = null) */ public function pluck($column, $key = null) { - $this->applyCriteria(); - $this->applyScope(); - - $lists = $this->model->pluck($column, $key); - - $this->resetModel(); - return $lists; + return $this->getQuery()->pluck($column, $key); } /** @@ -210,15 +205,9 @@ public function random() */ public function count(array $input = array()) { - $this->applyCriteria(); - $this->applyScope(); - $this->whereInputCriteria($input); - - $count = $this->model->count(); - - $this->resetModel(); - return $count; + + return $this->getQuery()->count(); } /** @@ -231,15 +220,9 @@ public function count(array $input = array()) */ public function max($field, array $input = array()) { - $this->applyCriteria(); - $this->applyScope(); - $this->whereInputCriteria($input); - - $max = $this->model->max($field); - - $this->resetModel(); - return $max; + + return $this->getQuery()->max($field); } /** @@ -252,15 +235,9 @@ public function max($field, array $input = array()) */ public function min($field, array $input = array()) { - $this->applyCriteria(); - $this->applyScope(); - $this->whereInputCriteria($input); - - $max = $this->model->min($field); - - $this->resetModel(); - return $max; + + return $this->getQuery()->min($field); } /** @@ -273,15 +250,9 @@ public function min($field, array $input = array()) */ public function sum($field, array $input = array()) { - $this->applyCriteria(); - $this->applyScope(); - $this->whereInputCriteria($input); - - $max = $this->model->sum($field); - - $this->resetModel(); - return $max; + + return $this->getQuery()->sum($field); } /** @@ -294,15 +265,9 @@ public function sum($field, array $input = array()) */ public function avg($field, array $input = array()) { - $this->applyCriteria(); - $this->applyScope(); - $this->whereInputCriteria($input); - - $avg = $this->model->avg($field); - - $this->resetModel(); - return $avg; + + return $this->getQuery()->avg($field); } /**