Answer the question
In order to leave comments, you need to log in
How to make Paginate for a related model (relationship)?
I have a selection, fully optimized queries, and exactly in such a collection as needed, but what about pagination?
Is it possible to add pagination for relations:
with('posts', 'posts.comments', 'posts.user', 'posts.comments.user') ?
Or is it not acceptable in this sample?
$locations = Locality::where('loc_id', $id)
->with('posts', 'posts.comments', 'posts.user', 'posts.comments.user')
->firstOrFail();
$locations = Locality::where('loc_id', $id)
->with(['posts' => function($query) {
$query->paginate(5);
}], 'posts.comments', 'posts.user', 'posts.comments.user')
->firstOrFail();
{{ $locations->posts->links() }}
Answer the question
In order to leave comments, you need to log in
https://laracasts.com/discuss/channels/laravel/how...
https://laracasts.com/discuss/channels/eloquent/ho...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question