Skip to content

[Request] Add methods to Paginator::make() which will return "current" items #26

Closed
@andrewryno

Description

@andrewryno

From my understanding of the Paginator class right now, when you want to use make() to paginate custom data not from Eloquent (in my case it's from Mongo), it doesn't actually handle returning the subset of data to be displayed on the current page.

Current code:

$perPage = 50;
$paginator = Paginator::make($data, count($data), $perPage);
$currentPage = Paginator::getCurrentPage();
$pagedData = array_slice($data, $currentPage * $perPage, $perPage);
// Pass $paginator and $pagedData to view

Wanted code:

// Remove count() call since we could just call it in the make() method
$paginator = Paginator::make($data, $perPage);
// Pass $paginator to view

Then in the view:

@foreach ($paginator->getRows() as $row)
    {{ $row->column }}
@endforeach

Currently getItems() just returns the items you put into the first argument of make(), so probably add getRows() or something similar to get the data which would just be an array_slice() call or similar.

Thoughts? Am I missing something in the current functionality?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions