P
P
Pavel2017-09-25 10:34:41
Laravel
Pavel, 2017-09-25 10:34:41

How to get paginator in related collection?

Hello. I have this code

$user = User::with(['relation' => function($query){
            $query->simplePaginate(10);
        }])->find($id);

In the user model, the associated model is displayed as a collection without any pagination properties. The request is executed correctly, with offset and limit, and if you add ?page=2 to the url, then everything will also work and I will get the second page. The trouble is that I don't get the Paginator, which means I don't know if there's a next page, which page is now, etc.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mokhirjon Naimov, 2017-09-25
@Palych_tw

$relation = User::find($id)->relation()->simplePaginate(10);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question