You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But when you override the method withResponse($request, $response) in the CompanyResource class, it's not called. That's because the ResponseResource#toResponse() function calls the $this->resource->withResponse(...). And $this->resource is an object of the class AnonymousResourceCollection.
You can solve this by creating an extra ResourceCollection collection like CompanyCollection and overrie the withResponse there. And not use the static function collection on the Resource class.
Or can't we just implement that when it's a anonymous collection, it calls the withResponse of the resource?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
When you have a resource class CompanyResource and you have an endpoint to list all companies. The controller looks like this:
But when you override the method withResponse($request, $response) in the CompanyResource class, it's not called. That's because the ResponseResource#toResponse() function calls the $this->resource->withResponse(...). And $this->resource is an object of the class AnonymousResourceCollection.
You can solve this by creating an extra ResourceCollection collection like CompanyCollection and overrie the withResponse there. And not use the static function collection on the Resource class.
Or can't we just implement that when it's a anonymous collection, it calls the withResponse of the resource?
Beta Was this translation helpful? Give feedback.
All reactions