adrolli/eloquent-mutators
Define reusable Eloquent accessors and mutators outside your models. Apply the same transformation logic across multiple models or multiple attributes on one model using a base model class or a trait, with config and extensible registration via a service provider.
title_case, slug, trim_whitespace) across all models, improving UX and API consistency.name, description, or price require uniform transformations.Adopt When:
trim_whitespace, slug).Look Elsewhere If:
"This package lets us standardize how data is formatted across our application—like automatically cleaning up text fields or generating SEO-friendly URLs—without writing repetitive code. It’s a low-risk, high-reward way to improve data quality and developer efficiency, especially as we scale. Think of it as a ‘copy-paste eliminator’ for our backend team."
Key Outcomes:
snake_case to kebab_case) require updates in one place.*"This package moves Eloquent accessors/mutators out of individual model files into a reusable, configurable system. Here’s how it helps you:
slug mutator once and apply it to Post, Product, and Category models.obfuscate_email) via the Mutator facade without touching model classes.Implementation:
composer require awobaz/eloquent-mutators).Model class or using the Mutable trait.$accessors = ['title' => 'trim_whitespace']).Mutator facade.Trade-offs:
Example Use Case: Instead of this in every model:
public function getTitleAttribute($value) {
return trim(strtolower($value));
}
Use this once in a config file and apply it everywhere:
protected $accessors = [
'title' => ['trim_whitespace', 'lower_case']
];
```"*
How can I help you explore Laravel packages today?