-
-
Save Elliot-Alexander/c1c05b56df155c4010e996a4aa8e0201 to your computer and use it in GitHub Desktop.
Laravel Vest Enforcer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Laravel server error enforcer, allows for a Laravel validation error response to be passed in to validate with Vest. | |
// Fields should use the same name between server and client, currently the enforcer only reports the first error. | |
// In order to use, pass response.data.errors, function expects the following format | |
// { | |
// email: ['error message here', 'error message 2'] | |
// password: ['Password is too weak'] | |
// } | |
export default function hasServerError (value, field, serverErrors) { | |
if (Object.keys(serverErrors).indexOf(field) !== -1) { | |
return { | |
pass: false, | |
message: serverErrors[field][0] | |
} | |
} | |
return { | |
pass: true, | |
message: () => '' | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment