当前位置: 首页>>代码示例>>PHP>>正文


PHP Builder::getQuery方法代码示例

本文整理汇总了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 . '%');
 }
开发者ID:kblais,项目名称:query-filter,代码行数:14,代码来源:QueryFilter.php

示例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'));
         }
     }
 }
开发者ID:visualturk,项目名称:user-field_type,代码行数:14,代码来源:QueryWithPermission.php

示例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]);
         }
     }
 }
开发者ID:khaliqgant,项目名称:Deep,代码行数:16,代码来源:JoinableScope.php

示例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;
 }
开发者ID:angejia,项目名称:pea,代码行数:11,代码来源:Model.php

示例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);
 }
开发者ID:reverserob,项目名称:laravel-mongodb,代码行数:44,代码来源:Builder.php

示例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());
                 });
             });
         }
     });
 }
开发者ID:kitbs,项目名称:vinfo,代码行数:25,代码来源:TranslatableSortable.php

示例7: checkQuery

 private function checkQuery(Builder $query)
 {
     //nobody gets anything
     if (count($query->getQuery()->wheres) < 1) {
         return $query->where('id', '<', 1);
     }
 }
开发者ID:hughfletcher,项目名称:nuticket,代码行数:7,代码来源:WhereNotify.php

示例8: getArchivedAtColumn

 protected function getArchivedAtColumn(Builder $builder)
 {
     if (count($builder->getQuery()->joins) > 0) {
         return $builder->getModel()->getQualifiedArchivedAtColumn();
     }
     return $builder->getModel()->getArchivedAtColumn();
 }
开发者ID:laratools,项目名称:laratools,代码行数:7,代码来源:ArchivableScope.php

示例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');
     }
 }
开发者ID:LaravelRepository,项目名称:eloquent-repository,代码行数:11,代码来源:EloquentSorter.php

示例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;
 }
开发者ID:apolune,项目名称:news,代码行数:13,代码来源:News.php

示例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');
 }
开发者ID:khaliqgant,项目名称:Deep,代码行数:14,代码来源:RelationshipEntry.php

示例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);
 }
开发者ID:nsoimaru,项目名称:Laravel51-starter,代码行数:14,代码来源:HasOneOrMany.php

示例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);
 }
开发者ID:bryanashley,项目名称:framework,代码行数:15,代码来源:HasOneOrMany.php

示例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();
     }
 }
开发者ID:dr3ads,项目名称:FeaturedTrait,代码行数:14,代码来源:FeaturedScope.php

示例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();
 }
开发者ID:Tapioca,项目名称:eloquent-versioning,代码行数:15,代码来源:VersioningScope.php


注:本文中的Illuminate\Database\Eloquent\Builder::getQuery方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。