Created
October 15, 2019 08:13
-
-
Save cron13/17232ba8091ba3d98efa6db76937c608 to your computer and use it in GitHub Desktop.
parse laravel dot notation errors response
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
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