當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Eloquent\Builder類代碼示例

本文整理匯總了PHP中Illuminate\Database\Eloquent\Builder的典型用法代碼示例。如果您正苦於以下問題:PHP Builder類的具體用法?PHP Builder怎麽用?PHP Builder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Builder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: scopeWithTag

 public static function scopeWithTag(Builder $query, $tags, $type = 'slug')
 {
     $tags = (new static())->prepareTags($tags);
     return $query->whereHas('tags', function ($query) use($type, $tags) {
         $query->whereIn($type, $tags);
     });
 }
開發者ID:phantomlight,項目名稱:programme-chameleon,代碼行數:7,代碼來源:TaggableTrait.php

示例2: process

 /**
  * @param Builder $src
  * @param OperationInterface|SortOperation $operation
  * @return mixed
  */
 public function process($src, OperationInterface $operation)
 {
     $field = $operation->getField();
     $order = $operation->getOrder();
     $src->orderBy($field, $order);
     return $src;
 }
開發者ID:view-components,項目名稱:eloquent-data-processing,代碼行數:12,代碼來源:SortProcessor.php

示例3: apply

 /**
  * Apply the scope to a given Eloquent query builder.
  * @param Builder $builder
  * @param Model $model
  */
 public function apply(Builder $builder, Model $model)
 {
     $builder->join('uris', function ($join) use($model) {
         $join->where('uris.owner_type', '=', get_class($model));
         $join->on('uris.owner_id', '=', $model->getTable() . '.' . $model->getKeyName());
     })->select([$model->getTable() . '.*', 'uris.uri']);
 }
開發者ID:jaffle-be,項目名稱:framework,代碼行數:12,代碼來源:SiteSluggableScope.php

示例4: __construct

 /**
  * Create a new relation instance.
  *
  * @param  Illuminate\Database\Eloquent\Builder
  * @param  Illuminate\Database\Eloquent\Model
  * @return void
  */
 public function __construct(Builder $query, Model $parent)
 {
     $this->query = $query;
     $this->parent = $parent;
     $this->related = $query->getModel();
     $this->addConstraints();
 }
開發者ID:hochanh,項目名稱:Bootsoft-Bowling,代碼行數:14,代碼來源:Relation.php

示例5: scopeVisibleTo

 /**
  * Scope a query to only include records that are visible to a user.
  *
  * @param Builder $query
  * @param User $actor
  * @return Builder
  */
 protected function scopeVisibleTo(Builder $query, User $actor = null)
 {
     if ($actor !== null) {
         $query->whereVisibleTo($actor);
     }
     return $query;
 }
開發者ID:redstarxz,項目名稱:flarumone,代碼行數:14,代碼來源:GroupRepository.php

示例6: handle

 /**
  * Handle the filter.
  *
  * @param Builder               $query
  * @param SearchFilterInterface $filter
  */
 public function handle(Builder $query, TableBuilder $builder, SearchFilterInterface $filter)
 {
     $stream = $filter->getStream();
     $model = $builder->getTableModel();
     /**
      * If the model is translatable then
      * join it's translations so they
      * are filterable too.
      *
      * @var EloquentQueryBuilder $query
      */
     if ($model->getTranslationModelName() && !$query->hasJoin($model->getTranslationTableName())) {
         $query->leftJoin($model->getTranslationTableName(), $model->getTableName() . '.id', '=', $model->getTranslationTableName() . '.' . $model->getRelationKey());
     }
     $query->where(function (Builder $query) use($filter, $stream) {
         foreach ($filter->getColumns() as $column) {
             $query->orWhere($column, 'LIKE', "%{$filter->getValue()}%");
         }
         foreach ($filter->getFields() as $field) {
             $filter->setField($field);
             $fieldType = $stream->getFieldType($field);
             $fieldTypeQuery = $fieldType->getQuery();
             $fieldTypeQuery->setConstraint('or');
             $this->container->call([$fieldTypeQuery, 'filter'], compact('query', 'filter', 'builder'));
         }
     });
 }
開發者ID:jacksun101,項目名稱:streams-platform,代碼行數:33,代碼來源:SearchFilterQuery.php

示例7: find

 /**
  * @param User $actor
  * @param Builder $query
  */
 public function find(User $actor, Builder $query)
 {
     // Hide discussions which have tags that the user is not allowed to see.
     $query->whereNotExists(function ($query) use($actor) {
         return $query->select(new Expression(1))->from('discussions_tags')->whereIn('tag_id', Tag::getIdsWhereCannot($actor, 'viewDiscussions'))->where('discussions.id', new Expression('discussion_id'));
     });
 }
開發者ID:lazyboywu,項目名稱:edufunbbs,代碼行數:11,代碼來源:DiscussionPolicy.php

示例8: 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

示例9: processWhere

 /**
  * @param Builder $query
  * @param $wheres
  */
 private function processWhere(Builder $query, $wheres)
 {
     $self = $this;
     foreach ($wheres as $where) {
         /** @var WhereParameter $where */
         $query->where(function (Builder $query) use($self, $where) {
             if ($comparison = $where->getComparison()) {
                 $query->where($comparison->getSubject(), $comparison->getOperator(), $comparison->getValue());
             }
             foreach ($where->getChildren() as $child) {
                 if ($child instanceof AndConjunction) {
                     $query->where(function (Builder $query) use($self, $child) {
                         $this->processWhere($query, [$child->getSubject()]);
                     });
                 } elseif ($child instanceof OrConjunction) {
                     $query->orWhere(function (Builder $query) use($self, $child) {
                         $this->processWhere($query, [$child->getSubject()]);
                     });
                 } else {
                     throw new \InvalidArgumentException("Got an unknown conjunction");
                 }
             }
         });
     }
 }
開發者ID:catlabinteractive,項目名稱:charon,代碼行數:29,代碼來源:ResourceController.php

示例10: build

 public function build(Builder $query)
 {
     $page = $this->page;
     return $query->join('pages_tags', 'tags.id', '=', 'pages_tags.tag_id')->join('pages', 'pages_tags.page_id', '=', 'pages.id')->where(function ($query) use($page) {
         $query->where('pages.id', '=', $page->getId())->orWhere('pages.parent_id', '=', $page->getId());
     })->groupBy('tags.id')->orderBy('tags.name', 'asc');
 }
開發者ID:robbytaylor,項目名稱:boom-core,代碼行數:7,代碼來源:AppliedToPageDescendants.php

示例11: addUnordered

 /**
  * Extend Builder with custom method
  *
  * @param \Illuminate\Database\Eloquent\Builder $builder
  */
 protected function addUnordered(Builder $builder)
 {
     $builder->macro('unordered', function (Builder $builder) {
         $this->remove($builder, $builder->getModel());
         return $builder;
     });
 }
開發者ID:czim,項目名稱:laravel-pxlcms,代碼行數:12,代碼來源:PositionOrderedScope.php

示例12: withRelatedCriterion

 public function withRelatedCriterion(QueryBuilder $query)
 {
     if ($this->related === null) {
         throw new \RuntimeException('No relationships defined in the repository. Eloquent does ' . 'not support reading relationships from the Model. Related ' . 'models must be defined in the $related property of the ' . 'repository.');
     }
     return $query->with($this->related);
 }
開發者ID:monospice,項目名稱:spicy-repositories,代碼行數:7,代碼來源:BasicCriteria.php

示例13: setKeysForSaveQuery

 /**
  * Set the keys for a save update query.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @return \Illuminate\Database\Eloquent\Builder
  */
 protected function setKeysForSaveQuery(Builder $query)
 {
     foreach ($this->getKeyName() as $key) {
         $query->where($key, '=', $this->getAttribute($key));
     }
     return $query;
 }
開發者ID:spira,項目名稱:api-core,代碼行數:13,代碼來源:CompoundKeyTrait.php

示例14: scopeSearch

 /**
  * @param Builder $query
  *
  * @return Builder
  */
 public function scopeSearch($query)
 {
     if (Input::has('q')) {
         $q = Input::get('q');
         $model = $this;
         $query->where(function ($query2) use($q, $model) {
             foreach ($model->getColumns() as $searchColumn) {
                 $table = $model->getTable();
                 $searchColumnExplode = explode('.', $searchColumn);
                 if (count($searchColumnExplode) > 1) {
                     $table = $searchColumnExplode[0];
                     $searchColumn = $searchColumnExplode[1];
                 }
                 switch (Schema::getColumnType($table, $searchColumn)) {
                     case 'integer':
                     case 'bigint':
                     case 'smallint':
                     case 'float':
                         if (is_numeric($q)) {
                             $query2->orWhere($table . '.' . $searchColumn, '=', (int) $q);
                         }
                         break;
                     case 'string':
                     case 'text':
                         $query2->orWhere($table . '.' . $searchColumn, 'ilike', "%{$q}%");
                         break;
                 }
             }
         });
     }
     return $query;
 }
開發者ID:jumper423,項目名稱:laravel-columns-search,代碼行數:37,代碼來源:Search.php

示例15: scopeFindSimilarSlugs

 /**
  * Query scope for finding "similar" slugs, used to determine uniqueness.
  *
  * @param \Illuminate\Database\Eloquent\Builder $query
  * @param \Illuminate\Database\Eloquent\Model $model
  * @param string $attribute
  * @param array $config
  * @param string $slug
  * @return \Illuminate\Database\Eloquent\Builder
  */
 public function scopeFindSimilarSlugs(Builder $query, Model $model, $attribute, $config, $slug)
 {
     $separator = $config['separator'];
     return $query->where(function (Builder $q) use($attribute, $slug, $separator) {
         $q->where($attribute, '=', $slug)->orWhere($attribute, 'LIKE', $slug . $separator . '%');
     });
 }
開發者ID:hilltool,項目名稱:eloquent-sluggable,代碼行數:17,代碼來源:Sluggable.php


注:本文中的Illuminate\Database\Eloquent\Builder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。