Paginator Bundle for the Symfony Framework.
composer require dwalczyk/paginator-bundle
// config/bundles.php
DWalczyk\Paginator\PaginatorBundle::class => ['all' => true]
Doctrine QueryBuilder is supported by default.
use DWalczyk\Paginator\PaginatorInterface;
#[Route('/users')]
public function __invoke(PaginatorInterface $paginator)
{
$res = $paginator->paginate(
$target = $this->getEm()->createQueryBuilder()->select('u')->from(User::class, 'u'),
$page = 1,
$itemsPerPage = 30
);
dump($res);
}
<?php
namespace App\Service;
use DWalczyk\Paginator\DataLoaderInterface;
class SamplePaginatorDataLoader implements DataLoaderInterface
{
public function loadItems(mixed $target, int $offset, int $limit): array
{
// some logic here
}
public function loadTotalCount(mixed $target): int
{
// some logic here
}
}
# config/services.yaml
services:
...
DWalczyk\Paginator\DataLoaderInterface: '@App\Service\SamplePaginatorDataLoader'
How can I help you explore Laravel packages today?