Skip to content

Commit

Permalink
get() method implement limit and offset
Browse files Browse the repository at this point in the history
  • Loading branch information
agungsugiarto committed Sep 28, 2020
1 parent 1a59955 commit 6c2bc9e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Contracts/RepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ interface RepositoryInterface
* Execute the query as a "select" statement.
*
* @param array $columns
* @param int $limit
* @param int $offset
* @return array
*/
public function get(array $columns = ['*']);
public function get(array $columns = ['*'], int $limit = 0, int $offset = 0);

/**
* Execute the query and get the first result.
Expand Down
4 changes: 2 additions & 2 deletions src/Eloquent/BaseRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ abstract class BaseRepository extends RepositoryAbstract implements RepositoryIn
/**
* @inheritdoc
*/
public function get(array $columns = ['*'])
public function get(array $columns = ['*'], int $limit = 0, int $offset = 0)
{
$results = $this->entity->select($columns)->findAll();
$results = $this->entity->select($columns)->findAll($limit, $offset);

$this->reset();

Expand Down
8 changes: 8 additions & 0 deletions tests/NewsRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ public function testRepositoryGet()
$this->assertNotEmpty($this->repository->get());
}

public function testRepositoryGetWithLimitAndOffset()
{
$getLimitOfset = $this->repository->get(['*'], 5, 0);

$this->assertNotEmpty($getLimitOfset);
$this->assertCount(5, $getLimitOfset);
}

public function testRepositoryFirst()
{
$this->assertNotEmpty($this->repository->first());
Expand Down

0 comments on commit 6c2bc9e

Please sign in to comment.