Question:
Is it possible to show new added Laravel resources API fields on specific routes?Example: I have a
UserResource
which has 3 fields – id, name and email
. I’m returning UserResource
in 10 routes. For 11th route added new field – posts
.Is it possible to show new
posts
field only for 11th route?Answer:
Of course you can, so you need to add two things. First inside of your controller in the method where you want to load posts do the followingUserResourse
class add the followingIf you have better answer, please add a comment about this, thank you!