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


PHP Builder::select方法代码示例

本文整理汇总了PHP中Illuminate\Database\Query\Builder::select方法的典型用法代码示例。如果您正苦于以下问题:PHP Builder::select方法的具体用法?PHP Builder::select怎么用?PHP Builder::select使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Database\Query\Builder的用法示例。


在下文中一共展示了Builder::select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: withCount

 /**
  * Add subselect queries to count the relations.
  *
  * @param  mixed  $relations
  * @return $this
  */
 public function withCount($relations)
 {
     if (is_null($this->query->columns)) {
         $this->query->select(['*']);
     }
     $relations = is_array($relations) ? $relations : func_get_args();
     foreach ($this->parseWithRelations($relations) as $name => $constraints) {
         // First we will determine if the name has been aliased using an "as" clause on the name
         // and if it has we will extract the actual relationship name and the desired name of
         // the resulting column. This allows multiple counts on the same relationship name.
         $segments = explode(' ', $name);
         if (count($segments) == 3 && Str::lower($segments[1]) == 'as') {
             list($name, $alias) = [$segments[0], $segments[2]];
         }
         $relation = $this->getHasRelationQuery($name);
         // Here we will get the relationship count query and prepare to add it to the main query
         // as a sub-select. First, we'll get the "has" query and use that to get the relation
         // count query. We will normalize the relation name then append _count as the name.
         $query = $relation->getRelationCountQuery($relation->getRelated()->newQuery(), $this);
         $query->callScope($constraints);
         $query->mergeModelDefinedRelationConstraints($relation->getQuery());
         // Finally we will add the proper result column alias to the query and run the subselect
         // statement against the query builder. Then we will return the builder instance back
         // to the developer for further constraint chaining that needs to take place on it.
         $column = snake_case(isset($alias) ? $alias : $name) . '_count';
         $this->selectSub($query->toBase(), $column);
     }
     return $this;
 }
开发者ID:sopnopriyo,项目名称:sopnopriyo,代码行数:35,代码来源:Builder.php

示例2: buildSubquery

 /**
  * Build the search subquery.
  *
  * @param  array  $words
  * @param  array  $columns
  * @param  string $groupBy
  * @param  float  $threshold
  * @return \Sofa\Searchable\Subquery
  */
 protected function buildSubquery(array $words, array $columns, $groupBy, $threshold)
 {
     $columns = $this->columns($columns);
     if (is_null($threshold)) {
         $this->threshold = array_reduce($columns, function ($sum, $column) {
             return $sum + $column->getWeight() / 4;
         });
     } else {
         $this->threshold = (double) $threshold;
     }
     if (strpos($groupBy, '.') === false) {
         $groupBy = $this->query->from . '.' . $groupBy;
     }
     $this->query->select($this->query->from . '.*')->groupBy($groupBy);
     $this->addSearchClauses($columns, $words, $this->threshold);
     return $this;
 }
开发者ID:jarektkaczyk,项目名称:laravel-searchable,代码行数:26,代码来源:Searchable.php

示例3: withCount

 /**
  * Add subselect queries to count the relations.
  *
  * @param  mixed  $relations
  * @return $this
  */
 public function withCount($relations)
 {
     if (is_null($this->query->columns)) {
         $this->query->select(['*']);
     }
     $relations = is_array($relations) ? $relations : func_get_args();
     foreach ($this->parseWithRelations($relations) as $name => $constraints) {
         // Here we will get the relationship count query and prepare to add it to the main query
         // as a sub-select. First, we'll get the "has" query and use that to get the relation
         // count query. We will normalize the relation name then append _count as the name.
         $relation = $this->getHasRelationQuery($name);
         $query = $relation->getRelationCountQuery($relation->getRelated()->newQuery(), $this);
         call_user_func($constraints, $query);
         $this->selectSub($query->getQuery(), snake_case($name) . '_count');
     }
     return $this;
 }
开发者ID:teckwei1993,项目名称:laravel-in-directadmin,代码行数:23,代码来源:Builder.php

示例4: buildQuery

 private function buildQuery()
 {
     $this->query = app(get_class($this->model));
     if (!empty($this->fields)) {
         $this->query = $this->query->select($this->fields);
     }
     if (!empty($this->relations)) {
         $this->relations = array_unique($this->relations);
         $this->query = $this->query->with($this->relations);
     }
     if (!empty($this->per_page)) {
         $this->query = $this->query->take($this->per_page);
     }
     if (count($this->conditions)) {
         foreach ($this->conditions as $condition) {
             $this->query = $this->query->where($condition['column'], $condition['operator'], $condition['value'], $condition['boolean']);
         }
     }
 }
开发者ID:bhutanio,项目名称:laravel-utilities,代码行数:19,代码来源:DbRepository.php

示例5: scopeGetByUserId

 /**
  * @param Builder $query
  * @param int $userId
  * @param int $parentId
  */
 public function scopeGetByUserId($query, $userId, $parentId = 0)
 {
     $minStatus = DB::table('messages_users as ms')->select(DB::raw('MIN(ms.status)'))->where('ms.parent_id', DB::raw('messages_users.message_id'))->orWhere('ms.message_id', DB::raw('messages_users.message_id'))->toSql();
     $query->select($this->getTable() . '.*', 'users.username as author', 'messages_users.status', DB::raw("({$minStatus}) as is_read"))->leftJoin('messages_users', $this->getTable() . '.id', '=', 'messages_users.message_id')->leftJoin('users', $this->getTable() . '.from_user_id', '=', 'users.id')->where('messages_users.user_id', (int) $userId)->where('messages_users.parent_id', (int) $parentId)->orderBy($this->getTable() . '.created_at', 'desc')->get();
 }
开发者ID:BlueCatTAT,项目名称:kodicms-laravel,代码行数:10,代码来源:Messages.php

示例6: scopeWithPermission

 /**
  * Select users which have the required permission
  * @param \Illuminate\Database\Query\Builder $query
  * @param string $permission Permission to check
  */
 public function scopeWithPermission($query, $permission)
 {
     $query->whereExists(function ($query) use($permission) {
         $query->select(DB::Raw('1'))->from('permission_role')->whereRaw('permission_role.role_id = users.role_id')->where('permission_role.permission_id', '=', function ($query) use($permission) {
             $query->select('id')->from('permissions')->where('ime', '=', $permission);
         });
     });
 }
开发者ID:Firtzberg,项目名称:Edu,代码行数:13,代码来源:User.php

示例7: addSelectQuery

 /**
  * Add selects to query builder
  * @param \Illuminate\Database\Query\Builder $query object is by reference
  */
 protected function addSelectQuery($query)
 {
     // Convert id into clients.id as id
     // Convert host.serverNum into hosts.server_num as host.serverNum ...
     // This one is odd becuase if column is in this entity, use COLUMN names
     // not property names because we have to transformStore next which requires column style.
     // BUT if column is subentity, then use entity names not colum names because we have already transformed the subentity
     // ex:
     /*array:9 [▼
         0 => "id"
         1 => "name"
         2 => "addressID"
         3 => "host.key"
         4 => "host.serverNum"
         5 => "address.address"
         6 => "address.city"
         7 => "address.stateKey"
         8 => "disabled"
       ]*/
     // Translates to
     /*
             array:9 [▼
      0 => "clients.id as id"
      1 => "clients.name as name"
      2 => "clients.address_id as address_id"
      3 => "hosts.key as host.key"
      4 => "hosts.server_num as host.serverNum"
      5 => "addresses.address as address.address"
      6 => "addresses.city as address.city"
      7 => "addresses.state as address.stateKey"
      8 => "clients.disabled as disabled"
             ]
     */
     $selects = [];
     if (isset($this->select)) {
         foreach ($this->select as $select) {
             $mappedSelect = $this->map($select, true);
             // host.serverNum
             list($table, $item) = explode('.', $select);
             if (str_contains($mappedSelect, '.')) {
                 list($table, $item) = explode('.', $mappedSelect);
                 $selects[] = "{$select} as {$table}.{$item}";
             } else {
                 $selects[] = "{$select} as {$item}";
             }
         }
     }
     // Add withCount (count column)
     if ($this->withCount) {
         $selects[] = DB::raw('count(*) as count');
     }
     $query->select($selects ?: ['*']);
     // Add distinct
     if ($this->distinct) {
         $query->distinct();
     }
 }
开发者ID:mreschke,项目名称:repository,代码行数:61,代码来源:DbStore.php

示例8: queryJoinBuilder

 /**
  * @param \Illuminate\Database\Query\Builder $query
  * @param  $relation
  *
  * @return \Illuminate\Database\Query\Builder
  *
  * @throws \Exception
  */
 private function queryJoinBuilder($query, $relation)
 {
     $relatedModel = $relation->getRelated();
     $relatedTable = $relatedModel->getTable();
     $parentModel = $relation->getParent();
     $parentTable = $parentModel->getTable();
     if ($relation instanceof HasOne) {
         $relatedPrimaryKey = $relation->getForeignKey();
         $parentPrimaryKey = $parentTable . '.' . $parentModel->primaryKey;
         return $query->select($parentTable . '.*')->join($relatedTable, $parentPrimaryKey, '=', $relatedPrimaryKey);
     } elseif ($relation instanceof BelongsTo) {
         $relatedPrimaryKey = $relatedTable . '.' . $relatedModel->primaryKey;
         $parentPrimaryKey = $parentTable . '.' . $relation->getForeignKey();
         return $query->select($parentTable . '.*')->join($relatedTable, $parentPrimaryKey, '=', $relatedPrimaryKey);
     } else {
         throw new \Exception();
     }
 }
开发者ID:kyslik,项目名称:column-sortable,代码行数:26,代码来源:Sortable.php

示例9: select

 /**
  * Set the columns to be selected.
  *
  * @param  array|mixed  $columns
  * @return $this
  */
 public function select($columns = ['*'])
 {
     parent::select($columns);
     $this->columns = $this->qualifyColumns($this->columns);
     return $this;
 }
开发者ID:laraplus,项目名称:translatable,代码行数:12,代码来源:QueryBuilder.php

示例10: scopeForSelectize

 /**
  * Lấy $take ebooks phục vụ selectize ebooks
  *
  * @param \Illuminate\Database\Query\Builder|static $query
  * @param int $take
  *
  * @return \Illuminate\Database\Query\Builder|static
  */
 public function scopeForSelectize($query, $take = 50)
 {
     return $query->select(['id', 'title'])->take($take);
 }
开发者ID:minhbang,项目名称:laravel-ebook,代码行数:12,代码来源:Ebook.php

示例11: scopeQueryDefault

 /**
  * @param \Illuminate\Database\Query\Builder|static $query
  *
  * @return \Illuminate\Database\Query\Builder|static
  */
 public function scopeQueryDefault($query)
 {
     return $query->select("{$this->table}.*");
 }
开发者ID:minhbang,项目名称:laravel-ilib,代码行数:9,代码来源:Reader.php

示例12: scopeWithUser

 /**
  * 
  * @param \Illuminate\Database\Query\Builder $query
  * @param int $user_id
  * @return \Illuminate\Database\Query\Builder
  */
 public function scopeWithUser($query, $user_id)
 {
     return $query->whereExists(function ($query) use($user_id) {
         $query->select(DB::Raw('1'))->from('predmet_user')->whereRaw('predmet_user.predmet_id = predmeti.id')->where('predmet_user.user_id', '=', $user_id);
     });
 }
开发者ID:Firtzberg,项目名称:Edu,代码行数:12,代码来源:Predmet.php

示例13: buildFields

 /**
  * @param Builder|QueryBuilder $queryBuilder
  * @param array $columns
  */
 protected function buildFields($queryBuilder, $columns = ['*'])
 {
     $queryBuilder->select($columns);
 }
开发者ID:williamoliveira,项目名称:eloquent-array-query-builder,代码行数:8,代码来源:ArrayBuilder.php

示例14: listExtendQuery

 /**
  * Attaches our column select statements to the query. Unfortunately, this
  * can't be done from listExtendQueryBefore. Select statements that are
  * added before processing the query will be removed by the behavior.
  *
  * @param  \Illuminate\Database\Query\Builder $query
  * @return \Illuminate\Database\Query\Builder
  */
 public function listExtendQuery($query)
 {
     $query->select('bedard_shop_products.*', 'inventory', 'price')->with(['current_price.discount' => function ($discount) {
         $discount->select('id', 'name', 'end_at');
     }])->selectStatus();
 }
开发者ID:scottbedard,项目名称:oc-shop-plugin,代码行数:14,代码来源:Products.php

示例15: paginated

 /**
  * Return the paginated result of the query
  *
  * @param   Builder $results    The query builder that contains all the clauses that have been applied
  * @param   array $filters      The filters that are to be applied to the query. The key identifies the database column, the value in the array is the value that is to be matched in the query
  * @param   int $size           The amount of results that we expect to receive from the paginator
  * @return mixed
  */
 protected function paginated($results, $filters = array(), $size = 25)
 {
     return $results->select($this->getTable() . '.*')->paginate($size)->appends($filters)->appends('size', $size);
 }
开发者ID:ixudra,项目名称:core,代码行数:12,代码来源:BaseEloquentRepository.php


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