src/Mediable.php
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);
    }
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);
    }
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 ) ; }
Attach a media entity to the model with one or more tags.
@param mixed           $media Either a string or numeric id, an array of ids, an instance of `Media` or an instance of `\Illuminate\Database\Eloquent\Collection`
@param string|string[] $tags  One or more tags to define the relation
@return void
Attach a media entity to the model with one or more tags .