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

Laravel Cycle Orm Adapter Laravel Package

wayofdev/laravel-cycle-orm-adapter

View on GitHub
Deep Wiki
Context7

Pagination

Pagination is provided by external package wayofdev/laravel-paginator.

Installation

composer require wayofdev/laravel-paginator

Usage with Repositories

Step 1: Define paginate() method in your Repository

Create a paginate() method in your abstract repository class that will return a CyclePaginator instance.

<?php

declare(strict_types=1);

namespace Infrastructure\Persistence\Cycle;

use Cycle\ORM\EntityManagerInterface;
use Cycle\ORM\Select;
use Cycle\ORM\Select\Repository as CycleRepository;
use Illuminate\Support\Collection;
use Spiral\Pagination\Paginator as SpiralPaginator;
use WayOfDev\Paginator\CyclePaginator;

class Repository extends CycleRepository
{
    /**
     * Create repository linked to one specific selector.
     *
     * [@param](https://github.com/param) Select<TEntity> $select
     */
    public function __construct(
        protected Select $select,
        protected EntityManagerInterface $entityManager
    ) {
        parent::__construct($select);
    }

    // ...

    public function paginate(int $perPage = 20, int $page = 1, string $pageName = 'page'): CyclePaginator
    {
        return $this->paginateQuery(
            $this->select(),
            $perPage,
            $page,
            $pageName,
        );
    }

    protected function paginateQuery(Select $query, int $perPage = 20, int $page = 1, string $pageName = 'page'): CyclePaginator
    {
        return new CyclePaginator(
            (new SpiralPaginator($perPage))->withPage($page)->paginate($query),
            $this->createCollection($query->fetchAll()),
            $pageName,
        );
    }

    protected function createCollection(iterable $items): Collection
    {
        return new Collection($items);
    }
}
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity