No way to know if a resource is being called collectively or not #54354
Unanswered
kachkolasa
asked this question in
Ideas
Replies: 1 comment
-
https://laravel.com/docs/11.x/eloquent-resources#resource-collections Can you check what is in $this->collection in your 2 mentioned cases? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently there is no way in a api resource to know if it's being called in a collection or it's a single resource.
For example:
$countries = Country::all();
return CountryResource::collection($countries);
In CountryResource, if you want to only attach the states when it's not a collection, you currently can't do that:
Beta Was this translation helpful? Give feedback.
All reactions