Last active
January 24, 2023 08:12
-
-
Save danLeBrown/b54986bb2f8dc5caddaadabca818a36b to your computer and use it in GitHub Desktop.
Collect Laravel validation error and use it to display alerts in React.js, Vue.js, etc...
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
// this is where alert data from the server is stored | |
const alertDataFromServer = [] | |
// this is the message relayed to the user | |
const messageToPush = [] | |
// res.data.data (alert data) comes from the server | |
alertDataFromServer.push(res.data.data) | |
alertDataFromServer.forEach((element) => { | |
const errorObjects = element.errors.errors | |
Object.keys(errorObjects).forEach((key) => { | |
obj[key].forEach((e) => { | |
messageToPush.push({ message: e }) | |
}) | |
}) | |
return true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment