本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder::getQuery方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::getQuery方法的具体用法?PHP Builder::getQuery怎么用?PHP Builder::getQuery使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Database\Eloquent\Builder
的用法示例。
在下文中一共展示了Builder::getQuery方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: like
/**
* Helper for "LIKE" filter
*
* @param String $column
* @param String $value
* @return Builder
*/
protected function like($column, $value)
{
if ($this->builder->getQuery()->getConnection()->getDriverName() == 'pgsql') {
return $this->builder->where($column, 'ILIKE', '%' . $value . '%');
}
return $this->builder->where($column, 'LIKE', '%' . $value . '%');
}
示例2: handle
/**
* Handle the command.
*
* @param RoleRepositoryInterface $roles
*/
public function handle(RoleRepositoryInterface $roles)
{
if (!$this->query->getQuery()->joins && ($permission = array_get($this->fieldType->getConfig(), 'permission'))) {
$accessible = $roles->findByPermission($permission);
if (!$accessible->isEmpty()) {
$this->query->join('users_users_roles', 'users_users_roles.entry_id', '=', 'users_users.id')->whereIn('users_users_roles.related_id', $accessible->lists('id'));
}
}
}
示例3: remove
/**
* Unjoin the tables
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model|null $model
* @return void
*/
public function remove(Builder $builder, EloquentModel $model = null)
{
foreach ($this->joins as $join) {
$index = array_search($join, $builder->getQuery()->joins, true);
if ($index !== false) {
unset($builder->getQuery()->joins[$index]);
}
}
}
示例4: newEloquentBuilder
public function newEloquentBuilder($query)
{
$builder = new Builder($query);
$builder->macro('key', function (Builder $builder) {
return $builder->getQuery()->key();
});
$builder->macro('flush', function (Builder $builder) {
return $builder->getQuery()->flush();
});
return $builder;
}
示例5: addHasWhere
/**
* Add the "has" condition where clause to the query.
*
* @param \Illuminate\Database\Eloquent\Builder $hasQuery
* @param \Illuminate\Database\Eloquent\Relations\Relation $relation
* @param string $operator
* @param int $count
* @param string $boolean
* @return \Illuminate\Database\Eloquent\Builder
*/
protected function addHasWhere(EloquentBuilder $hasQuery, Relation $relation, $operator, $count, $boolean)
{
$query = $hasQuery->getQuery();
// Get the number of related objects for each possible parent.
$relationCount = array_count_values($query->lists($relation->getHasCompareKey()));
// Remove unwanted related objects based on the operator and count.
$relationCount = array_filter($relationCount, function ($counted) use($count, $operator) {
// If we are comparing to 0, we always need all results.
if ($count == 0) {
return true;
}
switch ($operator) {
case '>=':
case '<':
return $counted >= $count;
case '>':
case '<=':
return $counted > $count;
case '=':
case '!=':
return $counted == $count;
}
});
// If the operator is <, <= or !=, we will use whereNotIn.
$not = in_array($operator, array('<', '<=', '!='));
// If we are comparing to 0, we need an additional $not flip.
if ($count == 0) {
$not = !$not;
}
// All related ids.
$relatedIds = array_keys($relationCount);
// Add whereIn to the query.
return $this->whereIn($this->model->getKeyName(), $relatedIds, $boolean, $not);
}
示例6: scopeWithRelatedTranslations
public function scopeWithRelatedTranslations(Builder $query, $relation, $andFields = [])
{
$model = $relation->getRelated();
$withFallback = $model->usePublicFallback();
$translatedAttributes = array_merge($model->translatedAttributes, $andFields);
$translatedAttributes = array_map(function ($attribute) use($model) {
return $model->getPublicTranslationsTable() . '.' . $attribute . ' AS ' . $model->getPublicTranslationsTable() . '_' . $attribute;
}, $translatedAttributes);
$query->withTranslations();
$translatedAttributes = array_merge((array) $query->getQuery()->columns, $translatedAttributes);
$query->select($translatedAttributes)->leftJoin($model->getPublicTranslationsTable(), $model->getPublicTranslationsTable() . '.' . $model->getRelationKey(), '=', $relation->getQualifiedForeignKey())->where(function ($query) use($model, $withFallback) {
$query->where($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->publicLocale());
if ($withFallback) {
$query->orWhere(function (Builder $q) use($model) {
$q->where($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->getPublicFallbackLocale($model->publicLocale()))->whereNotIn($model->getPublicTranslationsTable() . '.' . $model->getRelationKey(), function (QueryBuilder $q) use($model) {
$q->select($model->getPublicTranslationsTable() . '.' . $model->getRelationKey())->from($model->getPublicTranslationsTable())->where($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->publicLocale());
});
})->orWhere(function (Builder $q) use($model) {
$q->where($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->getPublicFallbackLocale())->whereNotIn($model->getPublicTranslationsTable() . '.' . $model->getRelationKey(), function (QueryBuilder $q) use($model) {
$q->select($model->getPublicTranslationsTable() . '.' . $model->getRelationKey())->from($model->getPublicTranslationsTable())->where($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->getPublicFallbackLocale($model->publicLocale()))->orWhere($model->getPublicTranslationsTable() . '.' . $model->getLocaleKey(), $model->publicLocale());
});
});
}
});
}
示例7: checkQuery
private function checkQuery(Builder $query)
{
//nobody gets anything
if (count($query->getQuery()->wheres) < 1) {
return $query->where('id', '<', 1);
}
}
示例8: getArchivedAtColumn
protected function getArchivedAtColumn(Builder $builder)
{
if (count($builder->getQuery()->joins) > 0) {
return $builder->getModel()->getQualifiedArchivedAtColumn();
}
return $builder->getModel()->getArchivedAtColumn();
}
示例9: sort
/**
* @param Builder $query
* @param SortInterface $sort
*/
public static function sort(Builder $query, SortInterface $sort)
{
/** @var Order $order */
foreach ($sort->orders() as $propertyName => $order) {
$query->getQuery()->orderBy($propertyName, $order->isAscending() ? 'ASC' : 'DESC');
}
}
示例10: scopeTickers
/**
* Scope a query to include tickers.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeTickers(Builder $query, $quantity)
{
$instance = ($combined = $this->combined) ? $query->getQuery()->newQuery()->from($this->getTable()) : $query;
$instance = $instance->where('type', 'ticker')->take($quantity);
$this->combined = true;
return $combined ? $query->unionAll($instance) : $instance;
}
示例11: scopeSiblings
/**
* Get the siblings of the specified entry ID
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param int|array $entryId
* @return \Illuminate\Database\Eloquent\Builder
*/
public function scopeSiblings(Builder $query, $entryId)
{
$entryId = is_array($entryId) ? $entryId : array($entryId);
$connection = $query->getQuery()->getConnection();
$tablePrefix = $connection->getTablePrefix();
return $query->join('relationships', 'relationships.child_id', '=', 'channel_titles.entry_id')->join($connection->raw("`{$tablePrefix}relationships` AS `{$tablePrefix}relationships_2`"), 'relationships_2.parent_id', '=', 'relationships.parent_id')->addSelect('*')->addSelect('relationships_2.child_id AS sibling_id')->whereIn('relationships_2.child_id', $entryId)->orderBy('relationships.order', 'asc')->groupBy('relationships_2.child_id')->groupBy('relationships.field_id')->groupBy('channel_titles.entry_id');
}
示例12: getRelationCountQuery
/**
* Add the constraints for a relationship count query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationCountQuery(Builder $query, Builder $parent)
{
if ($parent->getQuery()->from == $query->getQuery()->from) {
return $this->getRelationCountQueryForSelfRelation($query, $parent);
}
return parent::getRelationCountQuery($query, $parent);
}
示例13: getRelationQuery
/**
* Add the constraints for a relationship query.
*
* @param \Illuminate\Database\Eloquent\Builder $query
* @param \Illuminate\Database\Eloquent\Builder $parent
* @param array|mixed $columns
* @return \Illuminate\Database\Eloquent\Builder
*/
public function getRelationQuery(Builder $query, Builder $parent, $columns = ['*'])
{
if ($parent->getQuery()->from == $query->getQuery()->from) {
return $this->getRelationQueryForSelfRelation($query, $parent, $columns);
}
return parent::getRelationQuery($query, $parent, $columns);
}
示例14: getFeaturedAtColumn
/**
* Get the "deleted at" column for the builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @return string
*/
protected function getFeaturedAtColumn(Builder $builder)
{
if (count($builder->getQuery()->joins) > 0) {
return $builder->getModel()->getQualifiedFeaturedAtColumn();
} else {
return $builder->getModel()->getFeaturedAtColumn();
}
}
示例15: remove
/**
* Remove the scope from the given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function remove(Builder $builder, Model $model)
{
$table = $model->getVersionTable();
$query = $builder->getQuery();
$query->joins = collect($query->joins)->reject(function ($join) use($table) {
return $this->isVersionJoinConstraint($join, $table);
})->values()->all();
}