src/Traits/Attributable.php
public function setEntityAttribute(string $key, $value)
    {
        $current = $this->getEntityAttributeRelation($key);
        $attribute = $this->getEntityAttributes()->get($key);

        // $current will always contain a collection when an attribute is multivalued
        // as morphMany provides collections even if no values were matched, making
        // us assume at least an empty collection object will be always provided.
        if ($attribute->is_collection) {
            if (is_null($current)) {
                $this->setRelation($key, $current = new ValueCollection());
            }

            $current->replace($value);

            return $this;
        }

        // If the attribute to set is a collection, it will be replaced by the
        // new value. If the value model does not exist, we will just create
        // and set a new value model, otherwise its value will get updated.
        if (is_null($current)) {
            return $this->setEntityAttributeValue($attribute, $value);
        }

        if ($value instanceof Value) {
            $value = $value->getAttribute('content');
        }

        $current->setAttribute('entity_type', get_class($this));

        return $current->setAttribute('content', $value);
    }
public function setEntityAttribute(string $key, $value)
    {
        $current = $this->getEntityAttributeRelation($key);
        $attribute = $this->getEntityAttributes()->get($key);

        // $current will always contain a collection when an attribute is multivalued
        // as morphMany provides collections even if no values were matched, making
        // us assume at least an empty collection object will be always provided.
        if ($attribute->is_collection) {
            if (is_null($current)) {
                $this->setRelation($key, $current = new ValueCollection());
            }

            $current->replace($value);

            return $this;
        }

        // If the attribute to set is a collection, it will be replaced by the
        // new value. If the value model does not exist, we will just create
        // and set a new value model, otherwise its value will get updated.
        if (is_null($current)) {
            return $this->setEntityAttributeValue($attribute, $value);
        }

        if ($value instanceof Value) {
            $value = $value->getAttribute('content');
        }

        $current->setAttribute('entity_type', get_class($this));

        return $current->setAttribute('content', $value);
    }
public function setEntityAttribute ( string $ key , $ value ) { $ current = $ this -> getEntityAttributeRelation ( $ key ) ; $ attribute = $ this -> getEntityAttributes ( ) -> get ( $ key ) ; // $current will always contain a collection when an attribute is multivalued // as morphMany provides collections even if no values were matched, making // us assume at least an empty collection object will be always provided. if ( $ attribute -> is_collection ) { if ( is_null ( $ current ) ) { $ this -> setRelation ( $ key , $ current = new ValueCollection ( ) ) ; } $ current -> replace ( $ value ) ; return $ this ; } // If the attribute to set is a collection, it will be replaced by the // new value. If the value model does not exist, we will just create // and set a new value model, otherwise its value will get updated. if ( is_null ( $ current ) ) { return $ this -> setEntityAttributeValue ( $ attribute , $ value ) ; } if ( $ value instanceof Value ) { $ value = $ value -> getAttribute ( 'content' ) ; } $ current -> setAttribute ( 'entity_type' , get_class ( $ this ) ) ; return $ current -> setAttribute ( 'content' , $ value ) ; }
Set the entity attribute.

@param string $key
@param mixed  $value

@return mixed
Set the entity attribute .