You can always use https://laravel.com/docs/9.x/eloquent-resources#conditional-attributes to hide relations that are not eager loaded or merge additional fields if some other condition is met.
That should at least clean it up.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
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
@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.
Please or to participate in this conversation.