petritr's avatar
Level 15

How to do fast pagination

I need to do an pagination eg. Users::all() witch is the best approach? Fast and effect pagination ?

0 likes
4 replies
aurawindsurfing's avatar
Level 50
Users::paginate(20)

then in your balde:

<div class="container">
    @foreach ($users as $user)
        {{ $user->name }}
    @endforeach
</div>

{{ $users->links() }}

Where links is the paginator

Hope it helps!

1 like
petritr's avatar
Level 15

Thanks. What if i have a lot of users ? Would this be effective and fast ?

Cruorzy's avatar

Yes it only gets 20 users instead of all, behind the scenes its just a sql query with an offset.

1 like

Please or to participate in this conversation.