The LengthAwarePaginator woks... I had just to modify this line since offsets were wrong:
$currentPageSearchResults = $collection->slice($start, $perPage)->all();
Also had to add this above it to calculate the start correctly:
if ($currentPage==1) {
$start = 0;
}
else {
$start = ($currentPage-1) * $perPage;
}
Since for the first page $currentPage * $perPage equals 20 so on the first page it would start from 20th item (instead from 1st - zero one) and then at last page it would have nothing to show...
Anyway, this solution works... I hope that Paginator would soon be compatible with take() or limit() so this can be done easier...
In the meantime here's the entire code:
$collection = Videos::where('genre', $genre)
->orderby('rating', 'desc')
->with('actors')
->take(100)
->get()
$perPage = 20;
$currentPage = LengthAwarePaginator::resolveCurrentPage();
if ($currentPage == 1) {
$start = 0;
}
else {
$start = ($currentPage - 1) * $perPage;
}
$currentPageCollection = $collection->slice($start, $perPage)->all();
$paginatedTop100 = new LengthAwarePaginator($currentPageCollection, count($collection), $perPage);
$paginatedTop100->setPath(LengthAwarePaginator::resolveCurrentPath());
return view('top100videos', ['top100' => $paginatedTop100 ]);