pindab0ter/constrained-morph-to-for-laravel
Comment only linking to Post or Video, not User or Tag), reducing runtime errors and improving data integrity.Image or Video but not UserProfile).Notification models target only User, Team, or Project models.Review models to Product or Bundle types, excluding unrelated models.Adopt when:
morphTo) but requires explicit type constraints to prevent invalid associations (e.g., a Comment accidentally linked to a User).ModelNotFoundException) by validating polymorphic types at the query level.Look elsewhere if:
morphTo/morphWith).accessors, mutators, or middleware) for polymorphic constraints.For Executives:
*"This package adds ‘type safety’ to Laravel’s polymorphic relationships—ensuring a Comment can only link to Post or Video models, not arbitrary classes. It’s a lightweight, MIT-licensed solution that:
For Engineers:
"This extends Laravel’s morphTo to reject invalid model types at the query level. For example:
// Only allows Post or Video models
public function commentable() {
return $this->constrainedMorphTo([Post::class, Video::class]);
}
Key benefits:
For Architects/Tech Leads:
*"This package addresses a gap in Laravel’s polymorphic system by adding static type constraints to morphTo relationships. It’s particularly valuable for:
How can I help you explore Laravel packages today?