Skip to content

Commit

Permalink
Fix negative validation for pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
unicodeveloper committed Aug 17, 2015
1 parent 1a30db0 commit fabee3e
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Database\Eloquent;

use Closure;
use InvalidArgumentException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Pagination\Paginator;
Expand Down Expand Up @@ -265,9 +266,15 @@ public function lists($column, $key = null)
* @param string $pageName
* @param int|null $page
* @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
*
* @throws InvalidArgumentException
*/
public function paginate($perPage = null, $columns = ['*'], $pageName = 'page', $page = null)
{
if( $perPage <= 0) {
throw new InvalidArgumentException("Negative values can't be used to query results");
}

$total = $this->query->getCountForPagination();

$this->query->forPage(
Expand All @@ -291,6 +298,8 @@ public function paginate($perPage = null, $columns = ['*'], $pageName = 'page',
*/
public function simplePaginate($perPage = null, $columns = ['*'], $pageName = 'page')
{


$page = Paginator::resolveCurrentPage($pageName);

$perPage = $perPage ?: $this->model->getPerPage();
Expand Down

0 comments on commit fabee3e

Please sign in to comment.