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

dgagn's avatar
Level 3

Having a lot of Laravel API Resource for single resource

I am building a huge application. I want to know if theres a way to refactor having multiple API resources for a single resource? For example, in my app, I have UserSmallResource which includes the name, email, and avatar, UserMediumResource which includes the user's role name, the permissions, the name, the email, UserLargeResource which includes every possible fields for the resource. Is there a way to refactor it by using a single API resource? I am considering using GraphQL, but before I make that switch, I wanna know if there's a solution to my problem. Thanks a lot for reading

0 likes
3 replies
martinbean's avatar
Level 80

@dgagn GraphQL is not going to solve anything here. First ask yourself why you have so many different resources for the same model in the first place, when sparse fieldsets (basically specifying the fields to return in a query string parameter) could suffice instead.

1 like
dgagn's avatar
Level 3

@martinbean I just refactored the majority of the queries with spare fieldsets. Thank you

1 like

Please or to participate in this conversation.