Skip to main content

What Are Polymorphic Relations?

A polymorphic relation lets a single model belong to more than one other model using the same association. The classic example: comments that can belong to either a Post or a Video — without needing a separate post_comments and video_comments table.

How It Works

Two special columns store the type and ID of the parent:

1. Migration

2. Models

Comment — the “child” side, uses morphTo:
Post and Video — the “parent” sides, use morphMany:

3. Creating Polymorphic Records

4. Querying

Load comments for a post:
Load what a comment belongs to:
Load recent comments across all types:

5. morphOne — Single Polymorphic Child

Use morphOne when only one child record exists per parent — for example, each post has one FeaturedImage:

Common Use Cases

Important: Register Your Models

Polymorphic resolution works by looking up model classes by name in the registry. Make sure every model involved in the relation has static { this.register(); }: