public function setAttribute($attribute, $value)
    {
        // Give mutator priority over custom casts
        if ($this->hasSetMutator($attribute)) {
            $method = 'set' . studly_case($attribute) . 'Attribute';

            return $this->{$method}($value);
        }

        if (array_key_exists($attribute, $this->filterCustomCasts())) {
            /** @var $customCastObject CustomCastBase */
            $customCastObject = $this->getCustomCastObject($attribute);

            $this->attributes[$attribute] = $customCastObject->setAttribute($value);

            return $this;
        }

        parent::setAttribute($attribute, $value);
    }
public function setAttribute($attribute, $value)
    {
        // Give mutator priority over custom casts
        if ($this->hasSetMutator($attribute)) {
            $method = 'set' . studly_case($attribute) . 'Attribute';

            return $this->{$method}($value);
        }

        if (array_key_exists($attribute, $this->filterCustomCasts())) {
            /** @var $customCastObject CustomCastBase */
            $customCastObject = $this->getCustomCastObject($attribute);

            $this->attributes[$attribute] = $customCastObject->setAttribute($value);

            return $this;
        }

        parent::setAttribute($attribute, $value);
    }
public function setAttribute ( $ attribute , $ value ) { // Give mutator priority over custom casts if ( $ this -> hasSetMutator ( $ attribute ) ) { $ method = 'set' . studly_case ( $ attribute ) . 'Attribute' ; return $ this -> { $ method } ( $ value ) ; } if ( array_key_exists ( $ attribute , $ this -> filterCustomCasts ( ) ) ) { /** @var $customCastObject CustomCastBase */ $ customCastObject = $ this -> getCustomCastObject ( $ attribute ) ; $ this -> attributes [ $ attribute ] = $ customCastObject -> setAttribute ( $ value ) ; return $ this ; } parent :: setAttribute ( $ attribute , $ value ) ; }
Hook into setAttribute logic and enable our custom cast do the job.

This method is will override method in HasAttributes trait.

@param $attribute
@param $value

@throws \Exception

@return mixed
Hook into setAttribute logic and enable our custom cast do the job .