You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
collect({"posts.1.published": "The posts.1.published must be accepted.","posts.1.comments.0.message": "The posts.1.comments.0.message must be a string."}).groupBy((error,field)=>field.substring(0,7))
collect([
"posts.1.published" => "The posts.1.published must be accepted.",
"posts.1.comments.0.message" => "The posts.1.comments.0.message must be a string."
])->groupBy(fn($error, $field) => substr($field, 0, 7));
Expected Result:
[
"posts.1" => [
"The posts.1.published must be accepted.",
"The posts.1.comments.0.message must be a string.",
],
]
The text was updated successfully, but these errors were encountered:
SDIjeremy
added a commit
to SDIjeremy/collect.js
that referenced
this issue
Jan 21, 2023
Kinda annoying because right now the only solution I've found is to map it to an array, then groupBy, then map the groups, and finally map the group's items back into an object with mapWithKeys.
.map((error,field)=>({ error, field })).values().groupBy((error)=>error.field.substring(0,7)).map((errors,group)=>errors.mapWithKeys((error)=>[error.field.substring(0,7),error.error]))
❌ Javascript Collect.js
TypeError: this.items.forEach is not a function
https://runkit.com/embed/ffbieqiw4ine
✅ Laravel Collection
Expected Result:
The text was updated successfully, but these errors were encountered: