Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cosminc's avatar

Returning extra information in an API resource

Hello,

I have an API resource that returns all the users along with a count for posts, comments and ratings for each user.

I want to also include a summary in the returned array and I'm wondering which would be the best approach to do this.

I was thinking about using with() like the documentation states:

public function with($request)
{
    return [
        'meta' => [
            'summary' => '...'
        ],
    ];
 }

What do you think?

0 likes
2 replies
fylzero's avatar

@cosminc You can do this either as meta or top level meta as you're mentioning. Just use whichever you prefer organizationally.

1 like

Please or to participate in this conversation.