Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Laravel Morph Map Generator Laravel Package

spatie/laravel-morph-map-generator

Automatically generates and keeps Laravel Eloquent morph maps up to date. Models register themselves by implementing getMorphClass(), so you don’t forget to add entries. Optional auto-generation on app boot, configurable for custom model locations.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Polymorphic Relationships at Scale: Eliminates manual morph map maintenance for applications with 50+ polymorphic models (e.g., CMS platforms, SaaS with dynamic content types).
  • Developer Experience (DX) Roadmap: Reduces cognitive load for junior devs by automating boilerplate (aligns with "shift-left" DX initiatives).
  • Build vs. Buy: Justifies not building a custom solution for morph map management (low risk, MIT-licensed, battle-tested by Spatie).
  • Use Cases:
    • Media Libraries: Auto-register Image, Video, Document models for polymorphic mediaable() relationships.
    • Audit Trails: Dynamically track changes across Post, Comment, UserProfile without manual map updates.
    • Multi-Tenant Apps: Scale polymorphic features (e.g., tenantable()) without syncing maps across environments.

When to Consider This Package

  • Adopt if:

    • Your app uses polymorphic relationships (e.g., morphTo, morphWith) with >10 models.
    • You’re tired of php artisan morph:map or forget to update maps after adding models.
    • Your team prioritizes automation over manual processes (e.g., CI/CD-friendly, no runtime checks).
    • You’re using Laravel 8+ (compatible with recent versions).
  • Look Elsewhere if:

    • You need fine-grained control over morph keys (e.g., dynamic keys per environment).
    • Your app uses custom morph map logic (e.g., conditional registration).
    • You’re on Laravel <8 (though backports may exist).
    • Your team prefers explicit over convention (e.g., prefers manual maps for clarity).

How to Pitch It (Stakeholders)

For Executives: "This package eliminates a tedious, error-prone task—maintaining morph maps—by auto-registering models when they implement getMorphClass(). For apps with polymorphic features (e.g., media libraries, audit logs), it reduces dev time by ~10% and cuts deployment risks from forgotten map updates. MIT-licensed, zero dependents, and backed by Spatie’s track record—low risk, high ROI."

For Engineering: "Replace manual php artisan morph:map with zero-effort registration. Just add getMorphClass() to your models, and the package handles the rest. Works seamlessly with Laravel’s polymorphic system, supports all recent versions, and includes tests/PSR-12 compliance. Tradeoff: loses explicit map visibility, but gains reliability and speed."

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
milesj/emojibase
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport