getQuery() public method

Get the underlying query builder instance.
public getQuery ( ) : Builder
return Illuminate\Database\Query\Builder
Ejemplo n.º 1
0
 /**
  * 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 . '%');
 }
 /**
  * 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'));
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * 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]);
         }
     }
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 /**
  * 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);
 }
Ejemplo n.º 6
0
 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());
                 });
             });
         }
     });
 }
Ejemplo n.º 7
0
 private function checkQuery(Builder $query)
 {
     //nobody gets anything
     if (count($query->getQuery()->wheres) < 1) {
         return $query->where('id', '<', 1);
     }
 }
Ejemplo n.º 8
0
 protected function getArchivedAtColumn(Builder $builder)
 {
     if (count($builder->getQuery()->joins) > 0) {
         return $builder->getModel()->getQualifiedArchivedAtColumn();
     }
     return $builder->getModel()->getArchivedAtColumn();
 }
 /**
  * @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');
     }
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
Ejemplo n.º 11
0
 /**
  * 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');
 }
Ejemplo n.º 12
0
 /**
  * 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);
 }
Ejemplo n.º 13
0
 /**
  * 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);
 }
Ejemplo n.º 14
0
 /**
  * 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();
     }
 }
Ejemplo n.º 15
0
 /**
  * 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();
 }
Ejemplo n.º 16
0
 /**
  * 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)
 {
     $column = $model->getQualifiedDraftColumn();
     $query = $builder->getQuery();
     $query->wheres = collect($query->wheres)->reject(function ($where) use($column) {
         return $this->isDraftConstraint($where, $column);
     })->values()->all();
 }
Ejemplo n.º 17
0
 /**
  * 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)
 {
     $columns = $model->getGeometries();
     $query = $builder->getQuery();
     // $query->wheres = collect($query->wheres)->reject(function ($where) use ($column) {
     //     return $this->isSoftDeleteConstraint($where, $column);
     // })->values()->all();
 }
Ejemplo n.º 18
0
 protected function checkQueryGroupBy()
 {
     $groups = $this->query->getQuery()->groups;
     $keyGroup = $this->model->getQualifiedKeyName();
     if (empty($groups) || !in_array($keyGroup, $groups)) {
         $this->query->groupBy($keyGroup);
     }
 }
Ejemplo n.º 19
0
 public function excludeCriterion(QueryBuilder $query, $columns)
 {
     $columns = static::getArgumentsArray($columns, func_get_args());
     // Get the attributes of the model and filter out all but specified
     $schema = $query->getQuery()->getConnection()->getSchemaBuilder();
     $allColumns = $schema->getColumnListing($query->getModel()->getTable());
     $difference = array_diff($allColumns, $columns);
     return $query->select($difference);
 }
Ejemplo n.º 20
0
 /**
  * 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);
     }
     $query->select(new Expression('count(*)'));
     $otherKey = $this->wrap($query->getModel()->getTable() . '.' . $this->otherKey);
     return $query->where($this->getQualifiedForeignKey(), '=', new Expression($otherKey));
 }
Ejemplo n.º 21
0
 /**
  * Remove the scope from the given Eloquent query builder.
  *
  * @param Builder $builder
  * @param Model $post
  * @return void
  */
 public function remove(Builder $builder, Model $post)
 {
     $query = $builder->getQuery();
     unset($query->wheres[$this->whereIndex]);
     $query->wheres = array_values($query->wheres);
     $whereBindings = $query->getRawBindings()['where'];
     array_splice($whereBindings, $this->bindingIndex, $this->bindingCount);
     $query->setBindings(array_values($whereBindings));
 }
Ejemplo n.º 22
0
 /**
  * @param Builder $query
  */
 protected function applySorting(Builder $query)
 {
     $fields = $this->fields();
     $field = Input::get('sort');
     if (!isset($fields[$field])) {
         return;
     }
     $query->getQuery()->orderBy($this->qualifiedFieldName($this->model, $field, true), $this->sortDirection());
 }
Ejemplo n.º 23
0
 /**
  * Remove the scope from the given Eloquent query builder.
  *
  * @param  \Illuminate\Database\Eloquent\Builder $builder
  * @return void
  */
 public function remove(Builder $builder, Model $model)
 {
     $query = $builder->getQuery();
     unset($query->wheres[$this->where_index]);
     $where_bindings = $query->getRawBindings()['where'];
     unset($where_bindings[$this->binding_index]);
     $query->setBindings(array_values($where_bindings));
     $query->wheres = array_values($query->wheres);
 }
Ejemplo n.º 24
0
 /**
  * Remove scope from the query.
  * 
  * @param \Illuminate\Database\Eloquent\Builder  $builder
  * @param \Illuminate\Database\Eloquent\Model  $model
  * @return void
  */
 public function remove(Builder $builder, Model $model)
 {
     $query = $builder->getQuery();
     $bindingKey = 0;
     foreach ((array) $query->wheres as $key => $where) {
         if (str_is('is_admin', $key)) {
             $this->removeWhere($query, $key);
         }
     }
 }
Ejemplo n.º 25
0
 /**
  * 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)
 {
     $query = $builder->getQuery();
     foreach ((array) $query->wheres as $key => $where) {
         if ($where['column'] === $model->getTypeKeyName()) {
             unset($query->wheres[$key]);
             $query->wheres = array_values($query->wheres);
         }
     }
 }
Ejemplo n.º 26
0
 /**
  * Gets all the joined tables.
  *
  * @return array
  */
 public function getJoinedTables()
 {
     $joins = [];
     if (is_array($queryJoins = $this->query->getQuery()->joins)) {
         $joins = array_map(function ($join) {
             return $join->table;
         }, $queryJoins);
     }
     return $joins;
 }
Ejemplo n.º 27
0
 /**
  * Remove scope from the query
  *
  * @param \Illuminate\Database\Eloquent\Builder $builder
  * @param \Illuminate\Database\Eloquent\Model   $model
  */
 public function remove(Builder $builder, Model $model)
 {
     $query = $builder->getQuery();
     $column = $model->getQualifiedPositionColumn();
     foreach ((array) $query->orders as $key => $order) {
         if ($order['column'] == $column) {
             $this->removeOrderBy($query, $key);
         }
     }
 }
Ejemplo n.º 28
0
 /**
  * {@inheritdoc}
  */
 public function constraintBuilder(EloquentBuilder $builder, array $options)
 {
     if ($relations = $this->eagerLoads(array_get($options, 'simple'))) {
         $builder->with($relations);
     }
     $query = $builder->getQuery();
     if ($value = array_get($options, 'order', $this->defaultOrder)) {
         $this->order($query, $value);
     }
 }
Ejemplo n.º 29
0
 public function remove(Builder $builder, Model $model)
 {
     $query = $builder->getQuery();
     foreach ((array) $query->wheres as $key => $where) {
         if ($this->isTenantConstraint($model, $where, $this->tenant_col, 1)) {
             unset($query->wheres[$key]);
             $query->wheres = array_values($query->wheres);
             break;
         }
     }
 }
Ejemplo n.º 30
0
 /**
  * @param EloquentBuilder $builder
  * @param array $input
  */
 public function constraintBuilder(EloquentBuilder $builder, array $input)
 {
     $query = $builder->getQuery();
     /** @var BaseFilter $filter */
     foreach ($this->items as $filter) {
         $key = $filter->getDataKey();
         if (isset($input[$key])) {
             $filter->applyFilterConstraint($query, $input[$key]);
         }
     }
 }