Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laravel Vest Enforcer
// 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