Skip to content

Instantly share code, notes, and snippets.

@shin1x1
Last active June 23, 2019 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shin1x1/349653c89fd07a55915b5957df213ccb to your computer and use it in GitHub Desktop.
Save shin1x1/349653c89fd07a55915b5957df213ccb to your computer and use it in GitHub Desktop.
<?php
namespace Acme\Application\Action;
use Acme\Application\Repository\UserPaginatorRepository;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
final class UserListAction
{
private const PER_PAGE = 10;
public function __invoke(UserPaginatorRepository $repository)
{
$page = Paginator::resolveCurrentPage();
// Get the total number of items and one page of data using repository
$total = $repository->count();
$results = $repository->findUserList($page, self::PER_PAGE);
// Create a LengthAwarePaginator instance
$paginator = new LengthAwarePaginator($results, $total, static::PER_PAGE, $page);
return view('users.list', [
'paginator' => $paginator,
]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment