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


PHP Builder::distinct方法代碼示例

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


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

示例1: distinct

 /**
  * Force the query to only return distinct results.
  *
  * @return $this 
  * @static 
  */
 public static function distinct()
 {
     return \Illuminate\Database\Query\Builder::distinct();
 }
開發者ID:satriashp,項目名稱:tour,代碼行數:10,代碼來源:_ide_helper.php

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


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