Is it possible to make data object properties read-only? #468
Unanswered
jameshulse
asked this question in
Q&A
Replies: 1 comment
-
Making properties protected is the best solution here I guess. I want to stay away from magic methods as much as possible. I don't think we always want to include protected properties. But if it can be somehow configureable that would be great. I don't have time to implement such a thing, but I'm always open for well tested and documented PR's! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am using a data object in an Eloquent cast for a JSON column. When the data object is returned from the database I would prefer if it had public methods to update its state, and allow the application to read its properties but not modify them.
Is this currently possible?
Maybe another attribute on the constructor fields like #[Readonly] could use the magic __set() method to catch when a field is being incorrectly set.
Beta Was this translation helpful? Give feedback.
All reactions