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

Mustaffa's avatar

API response structure

What is the best practice if I have an API that returns an array for user status and every key of this response has it is logic it does not come from one model but multiple models with business logic? while the resource class accepts only one model. should I implement a custom class, for example, UserStatsResponse this class has a method return array for the structure that I need.

0 likes
3 replies
Mustaffa's avatar

@Ashraam I know the Eloquent API Resource of laravel the problem that it is accept only one model is there another way to pass multiple models in resource classes and implement some business logic?

Sinnbeck's avatar

@Mustaffa You just call it like this to allow it use an array of users (or whatever model you want to add)

UserStatResource::collection($users);

Please or to participate in this conversation.