Laravel API resources are a great tool to format json resources to be returned by an API endpoint. If you are not familiar with this part of the framework, the Laravel documentation will help you.
Now the purpose of this post is not to introduce you to this particular problem, and you’ll find great resources and packages to help you with this.
Yes, this trick is great for single resources (tipically in the show() method of our controller), but this will not work when calling `ProjectResource::collection(…
I hope this will help you to fix some resources; I’m using this code, or a variation of this, in my current projects, at Code 16.