當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。