Laravel - Database - Polymorphic Many To Many Relationships

Polymorphic "many to many" (morphToMany / morphedByMany) relationships may be created just like non-polymorphic "many to many" relationships:

    
    use App\Models\Tag;
    use App\Models\Video;
    
    $videos = Video::factory()
                ->hasAttached(
                    Tag::factory()->count(3),
                    ['public' => true]
                )
                ->create();
	

Of course, the magic has method may also be used to create polymorphic "many to many" relationships:

    
    $videos = Video::factory()
                ->hasTags(3, ['public' => true])
                ->create();