Mutators
Introduction
JCC-Eloquent supports attribute mutation at the model level through:
- method-based mutators and accessors (
setXAttribute,getXAttribute) - the
attributes()map withget/sethandlers
These run when you assign values through model properties, fill(...), or call getAttribute(...) / setAttribute(...).
Method-based mutators
Use set{Studly}Attribute to transform values before they are stored in _attributes.
When you set user.password = "secret" or call user.fill({ password: "secret" }), this mutator is used.
Method-based accessors
Use get{Studly}Attribute to customize values when reading attributes.
getAttribute("name") and property access (user.name) will use this accessor.
attributes() getter/setter handlers
For per-attribute definitions, override attributes() and return get / set handlers.
If both method-based and attributes() handlers exist for the same key, method-based accessors/mutators are checked first.
How mutators are triggered
Mutators/accessors run through model internals:
setAttribute(key, value)checksset{Studly}Attributefirst, thenattributes()[key].setgetAttribute(key)checksget{Studly}Attributefirst, thenattributes()[key].getfill(...)usessetAttribute(...), so mutators apply there too
Notes on casts
Model casts and mutators can be used together:
- mutator transforms incoming values
- casts normalize storage/read behavior for configured fields
Keep transformations predictable to avoid double-processing the same value.
