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