Plank\Mediable\Mediable::attachMedia PHP Метод

attachMedia() публичный Метод

Attach a media entity to the model with one or more tags.
public attachMedia ( mixed $media, string | array $tags ) : void
$media mixed Either a string or numeric id, an array of ids, an instance of `Media` or an instance of `\Illuminate\Database\Eloquent\Collection`
$tags string | array One or more tags to define the relation
Результат void
    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);
    }