intermediateLaravel
What are accessors and mutators?
Answer
Clear, interview-ready explanation
An accessor transforms a model attribute when it is read, while a mutator transforms an attribute before it is stored. For example, an accessor can present a normalized display value and a mutator can consistently format input before persistence.
Modern Laravel models commonly define these transformations with an Attribute-returning method. They are useful for small, model-specific representation rules, but they should not conceal expensive queries or substantial business workflows. Use dedicated services when the behavior has broader domain responsibility.