Laravel - Database - Polymorphic Relationships

Polymorphic relationships may also be created using factories. Polymorphic "morph many" relationships are created in the same way as typical "has many" relationships. For example, if a App\Models\Post model has a morphMany relationship with a App\Models\Comment model:

    
    use App\Models\Post;
    
    $post = Post::factory()->hasComments(3)->create();