Skip to content
Discussion options

You must be logged in to vote

yes it s possible; I had the same problem (on my e-commerce site)—the solution is simple
toRelationships() try something like this in the method:

public function toRelationships(Request $request): array
{
    return [
        'blog' => BlogResource::class,
        'author' => UserResource::class,
        'comments' => fn() => 
            CommentResource::collection(
                $this->whenLoaded('comments', fn() => 
                    $this->comments()->paginate(10)
                )
            ),
        'tags' => TagResource::class,
    ];
}

/*it also reduces server load*/

Replies: 4 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@Rasmus-Bertell
Comment options

@marius-ciclistu
Comment options

@marius-ciclistu
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@marius-ciclistu
Comment options

@colgecen
Comment options

Answer selected by Rasmus-Bertell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants