Look up by key
@param Illuminate\Database\Query\Builder $query Query building
@param string                            $key   Lookup key
@return Illuminate\Database\Query\Builder
775498
public function scopeKey(Illuminate\Database\Query\Builder $query, $key)
    {
        return $query->whereKey($key);
    }
394055
protected function getValueFromRelationQuery($query)
    {
        // Prevent looking up connected model when foreign keys are NULL to prevent query errors.

        /** @var MorphTo $query */
        $typeName = $query->getMorphType();
        $keyName  = $query->getForeignKey();

        if ( ! $this->model->{$typeName} || ! $this->model->{$keyName}) {
            return null;
        }

        $query = $this->prepareRelationQuery($query);

        return $this->getValueFromModel(
            $query->first()
        );
    }
1066358
protected function searchQuery(Builder $query, string $phrase): Builder
    {
        $fields = $this->getModel()::getFillableFields();

        return $query->where(function (Builder $query) use ($fields, $phrase) {
            foreach ($fields as $key => $field) {
                $method = $key == 0 ? 'where' : 'orWhere';

                if (strpos($field, '_at') === false) {
                    $query->{$method}($field, 'LIKE', '%' . $phrase . '%');
                }
            }

            return $query;
        });
    }
940666
protected function execute($query)
    {
        $query->execute($this->bindings);
        
        $this->bindings = [];
        $this->wheres   = [];

        return $query;
    }
1347798
public function scopeKeywords($query, $keyword)
    {
        return $query->where(function ($query) use ($keyword) {
            $query->where('name', 'LIKE', "%$keyword%")
            ->orWhere('description', 'LIKE', "%$keyword%");
        });
    }
1199367
private function lookupKey($key)
    {
        foreach ($this->pairs as $pair) {
            if ($this->keysAreEqual($pair->key, $key)) {
                return $pair;
            }
        }
    }
873648
public function query($query = NULL) {
        if (isset($query)) {
            $this->setQuery(self::cleanQuery($query));
            return $this;
        }
        return $this->getQuery();
    }
705270
public function search($query)
    {
        $classes = $this->getClassMetadata();
        return $this->_sm->getUnitOfWork()->loadCollection($classes, $query);
    }
549412
public function distinct($key, $query = [])
    {
        if ($query instanceof Closure) {
            // Store the callback
            $callback = $query;

            // Create a new Where filter.
            $query = new Query\Where();

            // trigger callback
            $callback($query);
        }

        if ($query instanceof Query\Where) {
            // Get the filter.
            $query = $query->getWhere();
        }

        return $this->collection->distinct($key, $query);
    }
1230867
public function lookup(Query $query)
    {
        $id = $this->serializeQueryToIdentity($query);

        $expiredAt = $this->expiredAt;

        return $this->cache
            ->get($id)
            ->then(function ($value) use ($query, $expiredAt) {
                // cache 0.5+ resolves with null on cache miss, return explicit cache miss here
                if ($value === null) {
                    return Promise\reject();
                }

                /* @var $recordBag RecordBag */
                $recordBag = unserialize($value);

                // reject this cache hit if the query was started before the time we expired the cache?
                // todo: this is a legacy left over, this value is never actually set, so this never applies.
                // todo: this should probably validate the cache time instead.
                if (null !== $expiredAt && $expiredAt <= $query->currentTime) {
                    return Promise\reject();
                }

                return $recordBag->all();
            });
    }
1294221
public function search($query)
    {
        if (!$this->searchEnabled) {
            throw new SdkException("Search is not available for " . $this->getResourceName());
        }

        if (!is_array($query)) $query = array('query' => $query);

        $url = $this->generateUrl($query, 'search');

        return $this->get(array(), $url);
    }
410207
public function fetch($query)
    {
        $result = $this->query($query);

        return $result->fetch(\PDO::FETCH_ASSOC);
    }
676034
protected function setUuidKeysForSaveQuery(Builder $query)
    {
        $query->where($this->getUuidKeyName(), '=', $this->getUuidKeyForSaveQuery());

        return $query;
    }
299706
public function queryParameter($key)
    {
        $keys = array_pluck($this->queryParameters, 'key');
        $queryParameters = array_combine($keys, $this->queryParameters);
       
        return $queryParameters[$key];
    }
259783
protected function _resolveKey($query)
    {
        if (is_string($this->_key)) {
            return $this->_key;
        }
        $func = $this->_key;
        $key = $func($query);
        if (!is_string($key)) {
            $msg = sprintf('Cache key functions must return a string. Got %s.', var_export($key, true));
            throw new RuntimeException($msg);
        }

        return $key;
    }
825572
protected function setKeysForSaveQuery(Builder $query)
    {
        if (isset($this->attributes[$this->getKeyName()])) {
            return parent::setKeysForSaveQuery($query);
        }

        $query->where($this->foreignKey, $this->getOriginal(
            $this->foreignKey, $this->getAttribute($this->foreignKey)
        ));

        return $query->where($this->relatedKey, $this->getOriginal(
            $this->relatedKey, $this->getAttribute($this->relatedKey)
        ));
    }
147712
def matches_query(self, key, query):
        
        dumped = query.dump()
        dumped['className'] = query._query_class._class_name
        self._add_condition(key, '$inQuery', dumped)
        return self