Mar 2, 2015
0
Level 7
Laravel 4.2 Pagination on New Collection Doesn't Work As Expected
I created a new Collection, paginating as one would and passing it to the view. But there's one problem. The pagination works as expected on page 1, but when I press next, it goes on page 2, but there's no content there, nor the pagination links. The code is as above.
//pull all threads ordered by decreasing date
$all_threads = Thread::orderBy('updated_at', 'DESC')->paginate(30);
$new = $all_threads->each(function($thread)
{
$upvotes = $this->vote->count_upvotes('thread', $thread->id);
$downvotes = $this->vote->count_downvotes('thread', $thread->id);
$thread->score = $this->feedranker->threadScore($thread->created_at->diffInDays(), $upvotes - $downvotes);
});
$collection = $new;
// Paginate
$perPage = 3; // Item per page (change if needed)
$currentPage = Input::get('page') - 1;
$pagedData = $collection->slice($currentPage * $perPage, $perPage)->all();
$collection= Paginator::make($pagedData, count($collection), $perPage);
Please or to participate in this conversation.