Add pagination links to front page
This commit is contained in:
parent
4cc9b4fa30
commit
eb4f479b97
2 changed files with 24 additions and 5 deletions
|
@ -30,17 +30,23 @@ class FrontPageController extends Controller
|
||||||
->merge($articles)
|
->merge($articles)
|
||||||
->merge($bookmarks)
|
->merge($bookmarks)
|
||||||
->merge($likes)
|
->merge($likes)
|
||||||
->sortByDesc('updated_at')
|
->sortByDesc('updated_at');
|
||||||
->chunk(10);
|
|
||||||
|
|
||||||
$page = $allItems->get($pageNumber - 1);
|
$lastPage = intval(floor($allItems->count() / 10)) + 1;
|
||||||
|
|
||||||
if (is_null($page)) {
|
$items = $allItems->forPage($pageNumber, 10);
|
||||||
|
|
||||||
|
if ($items->count() === 0) {
|
||||||
abort(404);
|
abort(404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$prevLink = ($pageNumber > 1) ? '/?page=' . ($pageNumber - 1) : null;
|
||||||
|
$nextLink = ($pageNumber < $lastPage) ? '/?page=' . ($pageNumber + 1) : null;
|
||||||
|
|
||||||
return view('front-page', [
|
return view('front-page', [
|
||||||
'items' => $page,
|
'items' => $items,
|
||||||
|
'prevLink' => $prevLink,
|
||||||
|
'nextLink' => $nextLink,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,5 +26,18 @@
|
||||||
@endforeach
|
@endforeach
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="paginator">
|
||||||
|
@if($prevLink)
|
||||||
|
<a href="{{ $prevLink }}">Prev</a>
|
||||||
|
@else
|
||||||
|
<a href="" class="disabled">Prev</a>
|
||||||
|
@endif
|
||||||
|
@if($nextLink)
|
||||||
|
<a href="{{ $nextLink }}">Next</a>
|
||||||
|
@else
|
||||||
|
<a href="" class="disabled">Next</a>
|
||||||
|
@endif
|
||||||
|
</div>
|
||||||
|
|
||||||
@include('templates.bio')
|
@include('templates.bio')
|
||||||
@stop
|
@stop
|
||||||
|
|
Loading…
Add table
Reference in a new issue