laravel-orion
laravel-orion copied to clipboard
feat: add the ability to create API routes with multiple route parameters
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 the User
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 bound KeyResolver
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.