src/Concerns/HasAttrWithMiddleware.php
public function setMiddlewareOrFallback(string $name, $value, $middleMan, $result = null)
    {
        // asserts instead of type-hints because this is a trait and another trait uses it.
        assert($middleMan instanceof MiddlewareDispatcher);

        if (! $middleMan->groupIsEmpty('setters')) {
            $result = $middleMan->callSetters($name, $value, $result);
        } elseif (is_object($result)) {
            $result = $result->$name = $value;
        } else {
            $result = $this->setVisibleAttribute($name, $value);
        }
        return $result;
    }
public function setMiddlewareOrFallback(string $name, $value, $middleMan, $result = null)
    {
        // asserts instead of type-hints because this is a trait and another trait uses it.
        assert($middleMan instanceof MiddlewareDispatcher);

        if (! $middleMan->groupIsEmpty('setters')) {
            $result = $middleMan->callSetters($name, $value, $result);
        } elseif (is_object($result)) {
            $result = $result->$name = $value;
        } else {
            $result = $this->setVisibleAttribute($name, $value);
        }
        return $result;
    }
Sets the value of the given attribute through middleware or locally as a fallback.

@param string $name
@param mixed $value
@param $middleMan
@param mixed $result
@return mixed