src/AttachableTrait.php
public function setAttaches($attaches, $type = 'name')
    {
        // Prepare the attaches
        $attaches = $this->prepareAttaches($attaches);

        // Get the current entity attaches
        $entityAttaches = $this->attaches->lists($type)->all();

        // Prepare the attaches to be added and removed
        $attachesToAdd = array_diff($attaches, $entityAttaches);
        $attachesToDel = array_diff($entityAttaches, $attaches);

        // Detach the attaches
        if (! empty($attachesToDel)) {
            $this->unattach($attachesToDel);
        }

        // Attach the attaches
        if (! empty($attachesToAdd)) {
            $this->attach($attachesToAdd);
        }

        return true;
    }
public function setAttaches($attaches, $type = 'name')
    {
        // Prepare the attaches
        $attaches = $this->prepareAttaches($attaches);

        // Get the current entity attaches
        $entityAttaches = $this->attaches->lists($type)->all();

        // Prepare the attaches to be added and removed
        $attachesToAdd = array_diff($attaches, $entityAttaches);
        $attachesToDel = array_diff($entityAttaches, $attaches);

        // Detach the attaches
        if (! empty($attachesToDel)) {
            $this->unattach($attachesToDel);
        }

        // Attach the attaches
        if (! empty($attachesToAdd)) {
            $this->attach($attachesToAdd);
        }

        return true;
    }
{@inheritdoc}