How do you handle key-value data structures in Laravel Data? #1082
Unanswered
RasmusGodske
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Laravel-data has become my must-have to all of my Laravel projects and I use it all of the time. However during my time working on it, I have multiple times found myself, trying to find a way around storing key/values. So I wanted to ask here, if anyone have any experience with this.
The Situation
I often find myself needing data structures that are more like "maps" or "dictionaries" than arrays, where the key itself is meaningful and I want to access items by that key. Think things like:
Or:
Where I need to efficiently look up by key, compare two such structures, and ensure they serialize consistently as JSON objects (not arrays).
My Questions
What do you all do in cases like this?
DataCollection
and work around the array-like behavior?{}
not arrays[]
?I'm particularly curious about:
DataCollection
works well for this, or if there are gotchas I should know aboutWhat I've Been Wondering
I keep second-guessing myself on whether I should:
DataCollection
work for this use caseHas anyone else wrestled with this? I feel like I might be overthinking it, but I also want to make sure I'm following good patterns.
Any insights, war stories, or "here's what I wish I'd known" would be super helpful!
Beta Was this translation helpful? Give feedback.
All reactions