grunburg
1 month ago
291
4
Laravel

Resource collection by user id

Posted 1 month ago by grunburg

I'm trying to get every post (paginated) by specific user defined in url e.g /users/1/posts/

So far I have added PostCollection to index action, but if I hit /users/{user}/posts/ endpoint, I get response with posts, all from diferent users. What am I doing wrong?

PostController.php

public function index(User $user): PostCollection
{
    return new PostCollection(Post::paginate(10));
}

PostCollection file is default, what should I add to make with work?

Please sign in or create an account to participate in this conversation.