Scope query with the given entity attribute.

@param \Illuminate\Database\Eloquent\Builder $builder
@param string                                $key
@param mixed                                 $value

@return \Illuminate\Database\Eloquent\Builder
182967
public function scopeHasAttribute(Builder $builder, string $key, $value): Builder
    {
        return $builder->whereHas($key, function (Builder $builder) use ($value) {
            $builder->where('content', $value)->where('entity_type', $this->getMorphClass());
        });
    }
1235721
public function setAttribute($key, $value)
    {
        if (in_array($key, $this->getTranslatable())) {
            $translation = $this->translateOrNew($this->getLocale());

            $translation->$key = $value;

            $this->translationCache[$this->getLocale()] = $translation;

            return $translation;
        }

        return parent::setAttribute($key, $value);
    }
767302
public function attr($key, $value = null, $force = false)
    {
        $attrs = $this->ctx->attrs ?: ($this->ctx->attrs = []);
        if (func_num_args() === 1) {
            return isset($attrs[$key]) ? $attrs[$key] : null;
        }

        $this->ctx->attrs[$key] = !array_key_exists($key, $attrs) || $force ? $value : $attrs[$key];

        return $this;
    }
1357037
public function fromQuery(Builder $builder, string $name, string $key = null): self
    {
        $key = $key ?? $builder->getModel()->getKeyName();

        return $this->setFromEloquent($builder, $name, $key);
    }
736567
public function handleBuilder($builder, $values)
    {
        return $builder->whereNotIn(
            $this->directiveArgValue('key', $this->definitionNode->name->value),
            $values
        );
    }
276456
public function query($key, $value = null)
    {
        if ($value) {
            return $this->replicate(['query' => [$key => $value]]);
        }

        return $this->replicate(['query' => $key]);
    }
323042
public function handleBuilder($builder, $value)
    {
        // Allow users to overwrite the default "where" clause, e.g. "whereYear"
        $clause = $this->directiveArgValue('clause', 'where');

        return $builder->{$clause}(
            $this->directiveArgValue('key', $this->definitionNode->name->value),
            $operator = $this->directiveArgValue('operator', '='),
            $value
        );
    }
222797
protected function convertAttributeValue($key, $value)
    {
        return $this->store->convertAttributeValue($this->getDataType($key), $value);
    }
853795
public function where($key, $operator = null, $value = null): IQueryBuilderHandler
    {
        // If two params are given then assume operator is =
        if (\func_num_args() === 2) {
            $value = $operator;
            $operator = '=';
        }

        if (\is_bool($value) === true) {
            $value = (int)$value;
        }

        return $this->whereHandler($key, $operator, $value);
    }
1352726
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);
    }
471134
public function scopeOfCreator(Builder $builder, Model $user): Builder
    {
        return $builder->where('created_by_type', $user->getMorphClass())->where('created_by_id', $user->getKey());
    }
40775
public function setAttribute($key, $value)
    {
        if ( ! $this->isTranslatableAttribute($key)) {
            return parent::setAttribute($key, $value);
        }

        foreach ((array) $value as $locale => $translation) {
            $locale = is_string($locale) ? $locale : null;
            $this->setTranslation($key, $translation, $locale);
        }

        return $this;
    }
581861
public function attribute($key, $value = null) {
        if (is_array($key)) {
            $this->_attributes = array_replace($this->_attributes, $key);
        } else {
            $this->_attributes[$key] = $value;
        }

        return $this;
    }
525897
public function withQueryParameter($key, $value)
    {
        $query = $this->getUri()->getQuery();
        parse_str($query, $params);
        $params[$key] = $value;

        return new self(
            $this->getMethod(),
            $this->getUri()->withQuery(http_build_query($params)),
            $this->getHeaders(),
            $this->getBody(),
            $this->getProtocolVersion(),
            $this->getRetries(),
            $this->getOptions(),
            $this->getServiceKey(),
            $this->getRequestKey()
        );
    }
690160
public function scopeWithAnyTenants(Builder $builder, $tenants): Builder
    {
        $tenants = $this->prepareTenantIds($tenants);

        return $builder->whereHas('tenants', function (Builder $builder) use ($tenants) {
            $builder->whereIn('id', $tenants);
        });
    }
888638
public function setAttribute($key, $value) {
    if (($key == static::$table_type_field) || (!$this->isInAllAttributes($key))) {
      throw new InvalidAttributeException("The attribute {$key} is non available.");
    }

    return parent::setAttribute($key, $value);
  }
518530
public function set($key, $value = null) {

        // Do not trigger state changes for relations
        if (!$this->hasRelation($key)) {

            // Only flag changed if the value is different
            if ($value != $this->get($key) && !in_array($key, $this->reserved)) {
                $this->_changed = true;
            }

            // Run the value through a mutator but do not set the mutator key
            if ($method = $this->hasMutator($key)) {
                $this->{$method}($value);

                return $this;
            }
        }

        $this->_attributes[$key] = $value;

        return $this;
    }