Add support for external validation attribute references #1051
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds two new methods to inject values into validation attributes:
Docs
Referencing the current authenticated user
If you need to reference the current authenticated user in your validation attributes, you can use the
AuthenticatedUserReference
:When you need to reference a specific property of the authenticated user, you can do so like this:
Using a different guard than the default one can be done by passing the guard name to the constructor:
Referencing container dependencies
If you need to reference a container dependency in your validation attributes, you can use the
ContainerReference
:It might be more useful to use a property of the container dependency, which can be done like this:
When your dependency requires specific parameters, you can pass them along:
Headsup
Some internal changes were made to make this work, while technically not exposed to the outside for anyone to use, you're technically able to do so.
RouteParameterReference
as parameter now acceptExternalReference
(RouteParameterReference
is aExternalReference
)normalizePossibleRouteReferenceParameter
in an ObjectValidationAttribute has been renamed tonormalizePossibleExternalReferenceParameter
RouteParameterReference
wasStringable
, we've removed this interface since it wasn't used by the package and it makes things rather unclear where the value of aRouteParameterReference
is called. You can continue using thegetValue
method which does the same.