Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Knp Paginator Bundle Laravel Package

knplabs/knp-paginator-bundle

View on GitHub
Deep Wiki
Context7

Manual counting

Note: this documentation concerns more advanced usage of ORM query pagination. Paginator cannot support two FROM components or composite identifiers, because it cannot predict the total count in the database.

The solution to that is simple and direct, you can provide the count manually through the hint on the query.

Usage example

<?php

$paginator = new Paginator();

$count = $entityManager
    ->createQuery('SELECT COUNT(c) FROM Entity\CompositeKey c')
    ->getSingleScalarResult()
;

$query = $entityManager
    ->createQuery('SELECT c FROM Entity\CompositeKey c')
    ->setHint('knp_paginator.count', $count)
;
$pagination = $paginator->paginate($query, 1, 10, ['distinct' => false]);

Distinction in this case also cannot be determined by paginator. It will take direct result of the query and limit with offset. In some cases you may need to use GROUP BY

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer
emarref/xdebug-bundle
emarref/pubnub-bundle
elriseio/finance-money-bundle