Home / Snippets / How to Get Current Pagination Data in Laravel
How to Get Current Pagination Data in Laravel cover

How to Get Current Pagination Data in Laravel

378

3 years ago

0 comments

To get the current pagination page data/items in Laravel you can chain the "items" method after the "paginate" method.
$posts = Post::query()
    ->whereNotNull('released_at')
    ->orderByDesc('released_at')
    ->paginate(12)
    ->items(); // only get the data

By accessing the pagination data like above you will be able to loop through the arrays in your views.
@foreach($posts as $post)
    <div>
        <h1>{{ $post->title }}</h1>
        <p>{{ $post->subtitle }}</p>
    </div>
@endforeach
notion avatar

Alaz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this