Skip to content

Commit

Permalink
Corrigido Filter Closure com WhereIn
Browse files Browse the repository at this point in the history
  • Loading branch information
Renato Moura committed Apr 30, 2018
1 parent 194d4a1 commit 5982d9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 52 deletions.
Expand Up @@ -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;
}

Expand Down
65 changes: 15 additions & 50 deletions src/NwLaravel/Repositories/Eloquent/AbstractRepository.php
Expand Up @@ -65,7 +65,10 @@ public function getQuery()
$this->applyCriteria();
$this->applyScope();

return $this->model;
$model = $this->model;

$this->resetModel();
return $model;
}

/**
Expand All @@ -89,7 +92,6 @@ public function searchAll(array $input, $orderBy = '', $limit = null, $skipPrese
->getQuery()
->limit($limit);

$this->resetModel();
return new BuilderResultset($query);
}

Expand Down Expand Up @@ -125,7 +127,6 @@ public function resultset($limit = null)
{
$query = $this->getQuery()->limit($limit);

$this->resetModel();
return new BuilderResultset($query);
}

Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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();
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down

0 comments on commit 5982d9f

Please sign in to comment.