Posts Learn Components Snippets Categories Tags Tools About
/

How to Get Current Pagination Data in Laravel

Learn how to get the current page items in Laravel pagination

Created on Jul 01, 2021

364 views

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

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

Load comments for How to Get Current Pagination Data in Laravel

)