Skip to content
This repository has been archived by the owner on Apr 20, 2018. It is now read-only.

Commit

Permalink
Merge pull request #5 from Askedio/dev
Browse files Browse the repository at this point in the history
Better default field.
  • Loading branch information
gcphost authored Aug 2, 2016
2 parents 297fe54 + df797cd commit 3de10c0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dd($paginated);
The last parameter is the field that will be used to paginate by, defaults to `id`.

```php
itemPaginate($perPage = null, $columns = ['*'], $pageName = 'from', $from = 0, $field = 'id')
itemPaginate($perPage = null, $columns = ['*'], $pageName = 'from', $from = 0, $field = null)
```

# Example Output
Expand Down
6 changes: 5 additions & 1 deletion src/ItemPaginatorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@ trait ItemPaginatorTrait
*
* @return ItemPaginator
*/
public function scopeItemPaginate($query, $perPage = null, $columns = ['*'], $pageName = 'from', $from = 0, $field = 'id')
public function scopeItemPaginate($query, $perPage = null, $columns = ['*'], $pageName = 'from', $from = 0, $field = null)
{
$from = $from ?: ItemPaginator::resolveCurrentPage($pageName, 0);

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

if (!$field) {
$field = $this->getTable() . '.id';
}

$query->where($field, '>', $from)->take($perPage + 1);

return new ItemPaginator($query->get($columns), $perPage, $from, [
Expand Down

0 comments on commit 3de10c0

Please sign in to comment.