-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add the ability to create API routes with multiple route parameters #271
feat: add the ability to create API routes with multiple route parameters #271
Conversation
…e check on the binding to make sure it matches the column type
This PR is ready for review. There were two test case fails. One a seg fault, and the other a unique constraint violation. Both edge cases. I am confident if they were rerun they would pass. Thanks, |
Hi @jonerickson, Thank you for the PR! I wonder if it would be possible to make the |
Great suggestion. Will update the PR! |
Hey @alexzarbn, after mulling this over, I am not coming up with any solution other than what I suggested. Using an out-of-the-box implementation of this package, using the As users implement this package, we have no way of knowing what the parameter name is they want to use in the In my case where I have all my routes as (using Does this make sense? Can you think of another way to do it? |
Hey @alexzarbn any second thoughts on this? I have been using my fork of this feature in prod and it has worked great. |
Hi @jonerickson, Sorry for the late response - past few months were quite hectic. Okay, that makes sense, thank you for looking into it! Merging ~ |
This PR aims to one, add a new feature, while two, allow more use cases for this package. Currently, when defining resources, if the route has another route parameter included, the package will not resolve the correct route parameter within the controller function definitions. Currently they are hardcoded to not allow more route parameters.
The current user story I am trying to fix with this PR is to define API routes like such:
https://xxxxxx.com/api/{apiVersion}/users/{id}
.We want our end users to be able to specify the API version using a route parameter. Within our application, we look at
apiVersion
and determine which HTTP resource to return to them.In the current state of the package, within the
HandlesStandardOperations::show($request, $key)
method,$key
will resolve to, in our user story,v1
, instead of theUser
ID.To fix this, we have introduced a backwards compatible key resolver that changes the function definition to
HandlesStandardOperations::show($request, ...$args)
to allow multiple route parameters to be resolved. Within a boundKeyResolver
class in the container, some simple logic is done to return which parameter should be used as the$key
for the further operations.If a user needs to customize the
KeyResolver
, they simply bind a new instance of their own custom implementation. I have included tests to illustrate.