Skip to content

Commit

Permalink
Merge pull request #8364 from jarektkaczyk/5.0-simplePaginate-on-BTW-…
Browse files Browse the repository at this point in the history
…and-HMT-relations

Add simplePaginate to BelongsToMany and HasManyThrough
  • Loading branch information
taylorotwell committed Apr 10, 2015
2 parents c5c5996 + b5debe2 commit ffc9662
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public function get($columns = array('*'))
*
* @param int $perPage
* @param array $columns
* @return \Illuminate\Pagination\Paginator
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function paginate($perPage = null, $columns = array('*'))
{
Expand All @@ -186,6 +186,24 @@ public function paginate($perPage = null, $columns = array('*'))
return $paginator;
}

/**
* Paginate the given query into a simple paginator.
*
* @param int $perPage
* @param array $columns
* @return \Illuminate\Contracts\Pagination\Paginator
*/
public function simplePaginate($perPage = null, $columns = array('*'))
{
$this->query->addSelect($this->getSelectColumns($columns));

$paginator = $this->query->simplePaginate($perPage, $columns);

$this->hydratePivotRelation($paginator->items());

return $paginator;
}

/**
* Chunk the results of the query.
*
Expand Down
16 changes: 15 additions & 1 deletion src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ protected function getSelectColumns(array $columns = ['*'])
*
* @param int $perPage
* @param array $columns
* @return \Illuminate\Pagination\Paginator
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*/
public function paginate($perPage = null, $columns = ['*'])
{
Expand All @@ -313,6 +313,20 @@ public function paginate($perPage = null, $columns = ['*'])
return $this->query->paginate($perPage, $columns);
}

/**
* Paginate the given query into a simple paginator.
*
* @param int $perPage
* @param array $columns
* @return \Illuminate\Contracts\Pagination\Paginator
*/
public function simplePaginate($perPage = null, $columns = ['*'])
{
$this->query->addSelect($this->getSelectColumns($columns));

return $this->query->simplePaginate($perPage, $columns);
}

/**
* Get the key for comparing against the parent key in "has" query.
*
Expand Down

0 comments on commit ffc9662

Please sign in to comment.