• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Eloquent\Builder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中Illuminate\Database\Eloquent\Builder的典型用法代码示例。如果您正苦于以下问题:PHP Builder类的具体用法?PHP Builder怎么用?PHP Builder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Builder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: addWithDrafts

 protected function addWithDrafts(Builder $builder)
 {
     $builder->macro('withDrafts', function (Builder $builder) {
         $this->remove($builder, $builder->getModel());
         return $builder;
     });
 }
开发者ID:k1ng440,项目名称:laravel-global-scope,代码行数:7,代码来源:PublishedScope.php


示例17: insertAndSetId

 /**
  * 重写插入方法
  * param Builder $query
  * param $attributes
  */
 protected function insertAndSetId(Builder $query, $attributes)
 {
     //默认父ID
     $attributes[$this->treeField['parent_key']] = array_get($attributes, $this->treeField['parent_key'], 1);
     //初始化配置
     $this->treeInit(app('NestedSetsService'));
     //开启事务,处理边界
     DB::beginTransaction();
     //边界处理,返回修改值
     $attributes = $this->nestend->insert($attributes[$this->treeField['parent_key']], $attributes, 'bottom');
     //保存数据
     $id = $query->insertGetId($attributes, $keyName = $this->getKeyName());
     //结果提交
     if ($attributes !== false && $id) {
         DB::commit();
     } else {
         DB::rollback();
         return false;
     }
     //赋值
     $this->setAttribute($keyName, $id);
     $this->setAttribute($this->treeField['parent_key'], $attributes[$this->treeField['parent_key']]);
     $this->setAttribute($this->treeField['level_key'], $attributes[$this->treeField['level_key']]);
     $this->setAttribute($this->treeField['left_key'], $attributes[$this->treeField['left_key']]);
     $this->setAttribute($this->treeField['right_key'], $attributes[$this->treeField['right_key']]);
 }
开发者ID:zsping1989,项目名称:margin-tree,代码行数:31,代码来源:TreeModel.php


示例18: scopeVisibleForUser

 /**
  * Scope a query to only include records that are visible to a user.
  *
  * @param  \Illuminate\Database\Eloquent\Builder  $query
  * @param  \Flarum\Core\Models\User  $user
  * @return \Illuminate\Database\Eloquent\Builder
  */
 protected function scopeVisibleForUser(Builder $query, User $user = null)
 {
     if ($user !== null) {
         $query->whereCan($user, 'view');
     }
     return $query;
 }
开发者ID:Qiang1234,项目名称:core,代码行数:14,代码来源:EloquentDiscussionRepository.php


示例19: build

 public function build(Builder $query)
 {
     $text = $this->title;
     return $query->whereNested(function (QueryBuilder $query) use($text) {
         return $query->where('title', 'like', "%{$text}%")->orWhere('description', 'like', "%{$text}%");
     });
 }
开发者ID:boomcms,项目名称:boom-core,代码行数:7,代码来源:TitleContains.php


示例20: constrainByModel

 /**
  * Constrain a query to an ability for a specific model.
  *
  * @param  \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder  $query
  * @param  \Illuminate\Database\Eloquent\Model  $model
  * @param  bool  $strict
  * @return void
  */
 protected function constrainByModel($query, Model $model, $strict = false)
 {
     $query->where(function ($query) use($model, $strict) {
         $query->where($this->table . '.entity_type', $model->getMorphClass());
         $query->where($this->abilitySubqueryConstraint($model, $strict));
     });
 }
开发者ID:JosephSilber,项目名称:bouncer,代码行数:15,代码来源:AbilitiesForModel.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Eloquent\Collection类代码示例发布时间:2022-05-23
下一篇:
PHP Capsule\Manager类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap