Description
I'm trying to filter the resources included on my request.
To give an example :
I have two models, a User and Posts.
/api/v1/users/123?include=posts&filter[posts][approved]=true
The above query would filter the users
that have approved posts and return them, but would still return all posts on the relationship ( approved or otherwise ).
Assuming the usage of a WhereHas
or a Where
filter on the UserSchema
.
This makes sense though, as I'm querying the users resource.
What I would actually like to do is :
A user has many posts, I want to query user "X", including their posts, but only approved posts.
From the documentation, filtering includes does not seem to be available.
I thought about having a custom filter, but I am a bit lost on how that would work.
Something like filter[included][posts][approved]=true
to distinguish that it's a filter applied to the included resource maybe. And an Included::make('posts')
filter that would rely on the filters defined on the PostSchema
OR
The query can be left as it is filter[posts][approved]=true
and the filter would be something along the lines of IncludedWhere
which would apply the filter to the included resource if requested, if not, it would act as a normal Where
filter ... this looks cleaner to me and leaves the specification on the schema rather than complicate the query params.