当前位置: 首页>>代码示例>>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;未经允许,请勿转载。