Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
andrewryno opened this issue Jan 13, 2013 · 4 comments

Comments

@andrewryno
Copy link
Contributor

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?

@taylorotwell
Copy link
Member

Wouldn't it better to slice the data coming out of Mongo instead of letting the Paginator do it?

@JoostK
Copy link
Contributor

JoostK commented Jan 13, 2013

There's the method Illuminate\Database\Query\Builder::buildRawPaginator which does this. Perhaps that one can be moved to the Paginator class.

@andrewryno
Copy link
Contributor Author

My initial reason behind not paginating straight ouf of Mongo was although we would only display the top X results, we need the the other results for graphing the data. So we display the top 50 results based on a column value, but we need all results in order to graph over time (since the top 50 can be from any time period).

To reduce the queries (granted it's negligible between 1 and 2) and also reduce the amount of reusable math in my controllers, it would be helpful (but obviously not necessary) to have those methods available. I don't really have a problem keeping it as it is, but just a thought I had while working with it.

@taylorotwell
Copy link
Member

I would suggest just slicing it and passing it into the paginator.

gonzalom pushed a commit to Hydrane/tmp-laravel-framework that referenced this issue Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants