public function attachMedia($media, $tags)
    {
        $tags = (array) $tags;
        $increments = $this->getOrderValueForTags($tags);

        $ids = $this->extractIds($media);

        foreach ($tags as $tag) {
            $attach = [];
            foreach ($ids as $id) {
                $attach[$id] = [
                    'tag' => $tag,
                    'order' => ++$increments[$tag],
                ];
            }
            $this->media()->attach($attach);
        }

        $this->markMediaDirty($tags);
    }