Closed sneakylenny closed 2 years ago
The closest thing I'm seeing that's already available to you is HasMany::make('relation')->canCount()->alwaysCountInRelationship()
. However, this only results in the meta.count
attribute appearing in responses when:
...?withCount=relation
.../posts/1/relationships/comments
).../posts/1/comments
)I recognize this isn't what you want (you wish to hit the show
route for a specific post
without the ?withCount
query param but still receive the relation count), but perhaps you can review the laravel-json-api/eloquent package to see if you can implement this feature and submit a pull request for it!
I don't have time for this at the moment. May reopen in the future.
It would be nice to have the ability to return the count in the response without the client having to query for it specifically. The feature would look like this:
So instead of having to query like this
I would be able to do just this
But still receive the same response:
It would make my client code cleaner since I need the relation count in most cases.
If this is already possible, help me out by referring to the docs. Maybe I missed it :p