javoscript/laravel-macroable-models
Adds Macroable support to Eloquent models, letting you define and register reusable model macros for dynamic methods at runtime. Great for extending models cleanly across packages and projects without touching the model class directly.
Developer Productivity & Velocity
Flexible Architecture for Experimentation
User::withFeatureX()) without schema changes.Domain-Specific Extensions
Product::applyDiscount() for seasonal promotions.User::calculateLifetimeValue() for analytics dashboards.Order::flagForReview() for moderation workflows.Roadmap Alignment
Avoid If:
User::hasRole() should likely be a trait or base model method).Adopt If:
"This package lets our dev team add custom functionality to Laravel models on the fly—like giving a model a 'temporary superpower' without rewriting code. For example, we could add a Product::applyBlackFridayDiscount() method for a one-time campaign without touching the core product logic. It’s like Lego blocks for model behavior: fast to assemble, easy to disassemble. This reduces dev time for experiments, A/B tests, or niche features, helping us ship faster without over-engineering."
Why it matters:
Risk: Minimal—MIT licensed, lightweight, and isolated to model extensions.
"This is a clean way to add ad-hoc methods to Eloquent models at runtime, using Laravel’s macro system. Think of it as a safer, more maintainable alternative to monkey-patching or dynamic eval().
Use Cases:
User::withPremiumFeatures() without cluttering the base model.Order::enableTaxExemption() for specific user segments.Invoice::processWithStripe()).How It Works:
Model::macro('customMethod', fn($model) => $model->doSomething());
$user->customMethod();
Trade-offs:
Alternatives: Compare with traits or query scopes—this wins for temporary or plugin-like extensions."*
How can I help you explore Laravel packages today?