You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allowing the validator to optionally return the validation rule parameters within the error message bag.
Use case
In a multilingual SPA, this would allow us to return the error from Laravel as a translation key while retaining access to the rule parameters, enabling us to reconstruct the error message on the frontend. That way, you only have to manage one set of translation files.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Idea
Allowing the validator to optionally return the validation rule parameters within the error message bag.
Use case
In a multilingual SPA, this would allow us to return the error from Laravel as a translation key while retaining access to the rule parameters, enabling us to reconstruct the error message on the frontend. That way, you only have to manage one set of translation files.
Example
Given the following validator
We'd currently get the following JSON
By passing the rule parameters we'd get the following JSON instead
Implementation
I am willing to implement this feature and send a PR.
I've already done some preliminary work to test my idea and it would most likely consist of modifying the following lines.
framework/src/Illuminate/Validation/Validator.php
Lines 822 to 824 in 7920ca5
It would be replaced by something like this only if parameters inclusion is enabled (how this is managed remains to be defined).
Things to keep in mind
@error
directive worksAny thoughts ?
Please share your thoughts about this idea and don't hesitate to point out any potential problems.
Beta Was this translation helpful? Give feedback.
All reactions