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.
slug, camel_case) cover common use cases, while the extend() method allows custom logic, making it adaptable to niche requirements (e.g., domain-specific transformations).config/mutators.php (e.g., renaming $accessors/$mutators properties), reducing merge conflicts in team environments.Mutator facade simplifies dynamic registration of extensions, useful for runtime configurations (e.g., tenant-specific rules).Mutator::apply()) may introduce micro-optimization concerns for high-throughput systems. Benchmarking recommended for critical paths.__get, __set) or observers may conflict. Audit existing models pre-integration.User, Product).snake_case for JSON APIs).slug, title_case) is frequent.Post, Tag) to validate the package’s behavior.Mutable) for models where extending the base class is infeasible.config/mutators.php with team conventions (e.g., property names, default behaviors).Mutator facade).slug may need VARCHAR instead of TEXT).php artisan mutators:install).config/app.php.Model class or add the Mutable trait to pilot models.MutatorServiceProvider (e.g., for business logic).assertEquals('slugified', $model->slug)).null values, empty strings).slug) propagate automatically to all models using them.README or wiki to aid onboarding.function (Model $model, ?string $value, string $key): string).User::all()) may slow queries. Consider lazy loading or query scopes.Redis) for frequently accessed attributes with expensive mutators.SELECT queries (e.g., preg_replace on large TEXT fields). Use database-level transformations (e.g., computed columns) where possible.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Mutator throws unhandled exception | Silent data corruption | Wrap mutators in try-catch; log errors. |
| Custom extension fails | Broken model behavior | Validate inputs; use fallback values. |
| Package version conflict | Integration failures | Pin version in composer.json. |
| Performance degradation | Slow API responses | Profile with Xdebug; optimize or cache. |
| Race conditions in side-effect mutators | Inconsistent data | Use database transactions or locks. |
trim_whitespace on already-trimmed data).slug requires string).How can I help you explore Laravel packages today?