Skip to content

Instantly share code, notes, and snippets.

@Elliot-Alexander
Created January 23, 2022 23:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elliot-Alexander/c1c05b56df155c4010e996a4aa8e0201 to your computer and use it in GitHub Desktop.
Save Elliot-Alexander/c1c05b56df155c4010e996a4aa8e0201 to your computer and use it in GitHub Desktop.
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