sebastiaanluca/laravel-auto-morph-map
App\Models\Post) in polymorphic relationships. This aligns well with architectures requiring database abstraction (e.g., microservices, multi-tenant apps, or legacy system integration).MorphMap definitions in models, reducing boilerplate and enforcing consistency. Ideal for large codebases with frequent polymorphic relationships (e.g., comments, notifications, or activity logs).MorphMap definitions with auto-discovery via configuration (e.g., config/automorphmap.php). No model-level modifications needed for basic use.Comment::where('commentable_type', 'App\Models\Post')) will break unless the package’s aliases are retroactively applied. Requires migration planning.AutoMorphMap::booted) and service providers, allowing granular control over edge cases.commentable_type values from FQCNs to aliases after deployment requires careful handling (e.g., data migration scripts, downtime).commentable_type values in production? (e.g., batch updates, downtime, or a hybrid approach.)post, video vs. app_post, app_video) Will this conflict with existing database constraints?morphClass (if using PHP 8+).commentable_type values and their FQCNs.automorphmap.php to define aliases (e.g., 'App\Models\Post' => 'post').commentable_type values to aliases (e.g., using Laravel’s DB::update).Post::whereMorph('commentable', 'post')).commentable_type parsing.illuminate/support).MorphMap changes in newer Laravel).stancl/tenancy). Use composer’s replace or alias namespaces to avoid conflicts.AutoMorphMap exceptions (e.g., unresolved classes).php artisan morph:map:list).automorphmap.php).commentable_type remain effective with shorter aliases.App\Models\Post → post), but this is negligible for most apps.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Alias configuration error | Polymorphic queries fail silently | Use try-catch in queries; log unresolved classes. |
| Database migration error | Data corruption or query failures | Backup before migration; test rollback procedure. |
| Package incompatibility (Laravel/PHP) | Integration breaks | Fork the package; isolate in a module until fixed. |
| Dynamic class not auto-discovered | Unpredictable morph map failures | Explicitly define dynamic classes in config or use events (AutoMorphMap::booted). |
| Caching issues | Stale morph maps in production | Clear config/cache on deploy; use php artisan config:clear. |
How can I help you explore Laravel packages today?