Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
parse laravel dot notation errors response
computed: {
parsedErrors() {
const parseDotNotation = function(str, val, obj) {
let currentObj = obj,
keys = str.split('.'),
i, l = Math.max(1, keys.length - 1),
key
for (i = 0; i < l; ++i) {
key = keys[i]
currentObj[key] = currentObj[key] || {}
currentObj = currentObj[key]
}
currentObj[keys[i]] = val
delete obj[str]
}
const expand = function (obj) {
for (let key in obj) {
if (obj.hasOwnProperty(key) && key.indexOf('.') !== -1) {
parseDotNotation(key, obj[key], obj)
}
}
return obj
}
return expand(this.errors)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.