danialm's avatar

pagination problem

Hello, I want to display a book. Everything is correct. But I want the comments to be in the form of a paginate. Only the comments. What is the solution? My code:

public function show(Book $book) { return $book->load(['categories', 'comments'])->toResource(); }

I want the comments to be in the form of a pitch.

0 likes
1 reply
Snapey's avatar

if your top model is a single model, then you don't need eager loading.

Suppose you already have $book

$comments = $book->comments()->paginate(10);

then pass both $book and $comments to the view.

Please or to participate in this conversation.