Skip to content

Commit

Permalink
Added getIn() and getNotIn() query methods
Browse files Browse the repository at this point in the history
  • Loading branch information
micheleangioni committed Aug 29, 2015
1 parent 901e19a commit 5884743
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ The `AbstractEloquentRepository` empowers automatically our repositories of the
- getBy(array $where = array(), array $with = array())
- getByLimit($limit, array $where = array(), array $with = array())
- getByOrder($orderBy, array $where = array(), array $with = array(), $order = 'desc', $limit = 0)
- getIn($whereInKey, array $whereIn = array(), $with = array(), $orderBy = NULL, $order = 'desc', $limit = 0)
- getNotIn($whereNotInKey, array $whereNotIn = array(), $with = array(), $orderBy = NULL, $order = 'desc', $limit = 0)
- has($relation, array $where = array(), array $with = array(), $hasAtLeast = 1)
- hasFirst($relation, array $where = array(), array $with = array(), $hasAtLeast = 1)
- hasFirstOrFail($relation, array $where = array(), array $with = array(), $hasAtLeast = 1)
Expand Down
35 changes: 35 additions & 0 deletions src/MicheleAngioni/Support/Repos/AbstractEloquentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,41 @@ public function getByOrder($orderBy, array $where = array(), array $with = array
return $query->get();
}


public function getIn($whereInKey, array $whereIn = array(), $with = array(), $orderBy = NULL, $order = 'desc', $limit = 0)
{
$query = $this->make($with);

$query = $query->whereIn($whereInKey, $whereIn);

if($orderBy) {
$query = $query->orderBy($orderBy, $order);
}

if($limit) {
$query = $query->take($limit);
}

return $query->get();
}

public function getNotIn($whereNotInKey, array $whereNotIn = array(), $with = array(), $orderBy = NULL, $order = 'desc', $limit = 0)
{
$query = $this->make($with);

$query = $query->whereNotIn($whereNotInKey, $whereNotIn);

if($orderBy) {
$query = $query->orderBy($orderBy, $order);
}

if($limit) {
$query = $query->take($limit);
}

return $query->get();
}

/**
* Return all results that have a required relationship
*
Expand Down

0 comments on commit 5884743

Please sign in to comment.