To paginate comments, you can use Laravel's built-in pagination method. Here's an example of how you can modify your code to achieve this:
In your Recipe.php model, modify the comments() method to include pagination:
public function comments()
{
return $this->hasMany(Comment::class)->orderBy('created_at', 'desc');
}
In your view, replace the current foreach loop with the following code:
@foreach ($recipe->comments()->paginate(10) as $comment)
<x-recipes.recipe-comment :comment="$comment" />
@endforeach
This will display 10 comments per page. You can adjust the number as needed.
In your Comment.php model, remove the show() method as it is not needed for this functionality.
That's it! Your comments should now be paginated.