Replies: 1 comment
-
validOrFail() - Userland implementation (hacky code, only to prototype) Single value validation
Returns single value or fails with HTTP Response 400
Returns single value or fails with \Exception Implementation:
Multiple values: It's still possible to pass arrays with multiple values:
Returns multiple values or fails with \Exception |
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
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:
Example:
$uuid = Validator::validOrFail($uuid, 'uuid|exists:users,uuid', Response::HTTP_BAD_REQUEST);
In this case, the submitting user should not get any meaningful error messages as feedback, if the uuid is invalid. The user sees only a "HTTP Status code 400" Error Page.
The developer in DEBUG mode sees the exception which includes the error messages (from $validator->messages()->toJson()).
Heres is how the signature of validOrFail could look like:
The default exception thrown by validOrFail() is still the regular Exception. So it's easy to add a try/catch block too.
It's still possible to pass the parameters as an array.
Current workaround without validOrFail(), for example in Livewire
Beta Was this translation helpful? Give feedback.
All reactions