Replies: 1 comment
-
Hi! I've never used the package as a route model binding but it's definitely an interesting use case. I think most people indeed just create the However, I have used an extended Hopefully this answers your question, good luck! |
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
-
Hello,
We use this package for building an API. We use Laravel Resources for the response of the API and all relations are conditionally appended to the Resources like this:
I was trying to setup the Spatie query builder to be used when resolving RouteModelBinding so I can request certain relations on a model when fetching a single model or even when updating a model.
I kinda got it working by placing the following in my
RouteServiceProvider
:This works when
order
is the only thing being resolved from the url:/api/orders/{order}
But when I have a nested resource this fails because the filters and relations in the request (intended for
order-lines
) are applied when resolving theorder
as well:/api/orders/{order}/order-lines
This made me wonder how other people use this package. Do you use the Spatie Query Builder at all for routes other than the index? And if not, how do you determine the relations that should be loaded in these other methods?
Beta Was this translation helpful? Give feedback.
All reactions