Constraining Laravel's MorphTo relation

Update: This is now available as a package on Packagist: pindab0ter/constrained-morph-to-for-laravel , source on GitHub . In a project with a polymorphic one-to-one MorphTo relationship, you might want to constrain the relationship to a specific model type. Say, for example , that you have a Comment model that can belong to either a Post or a Video ; commentable s. posts id - integer title -…